#include <stdio.h>
#include <stdint.h>
uint8_t is_circular_match(uint16_t reg, uint16_t target) {
uint16_t bit,res=reg,news;
int i,pos;
for(i=1;i<=15;i++){
res=(res<<1);
bit=reg>>(16-i)&1;
res|=bit<<0;
news=res&0xFFFF;
if(news==target)
return 1;
}
return 0;
}
int main() {
uint16_t reg, target;
scanf("%hu %hu", ®, &target);
printf("%hhu", is_circular_match(reg, target));
return 0;
}