#include <stdio.h>
#include <stdint.h>
uint8_t is_circular_match(uint16_t reg, uint16_t target) {
// Your code here
int n=1;
uint16_t tmp=0;
while(n<=16) {
tmp = ((reg << n) | (reg >> (16-n)));
// printf("%d\n",tmp);
if(tmp == target) return 1;
n++;
}
n=1; tmp=0;
while(n<=16) {
tmp = ((reg >> n) | (reg << (16-n)));
if(tmp == 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;
}