#include <stdio.h>
#include <stdint.h>
uint8_t is_circular_match(uint16_t reg, uint16_t target) {
int ex;
int n = 15;
uint16_t temp;
temp = reg;
//left rotation
while(n){
ex = temp & 0x8000;
temp = temp << 1;
if(ex) temp |= 0x0001;
else temp |= 0x0000;
if(temp == target) return 1;
n--;
}
return 0;
}
int main() {
uint16_t reg, target;
scanf("%hu %hu", ®, &target);
printf("%hhu", is_circular_match(reg, target));
return 0;
}