a;main(b){for(scanf("%d%d",&a,&b);b>1;a-=a/b/b--);a=!printf("%d",a);}