#include <stdio.h>
#include <stdint.h>
uint8_t is_circular_match(uint16_t reg, uint16_t target) {
// Your code here
int n =15;
while (n!=0){
uint16_t left_cir_match = reg <<n | reg >>(16-n);
uint16_t rig_cir_match = reg >>n |reg <<(16-n);
if(left_cir_match==target || rig_cir_match == 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;
}