a[1<<22];s,n,k,j;main(i){for(scanf("%d%d",&n,&k);i++=k)if(!a[i])for(j=0;j<2e6;a[j+=i]++);s=!printf("%d",s);}