def main(): import sys input = sys.stdin.readline P, N = map(int, input().split()) if N == 1: print(0) exit() flg = 0 if N * 2 > P: flg = 1 N = P - N Q = (P - (N - P%N))//N if Q%4 == 2 or Q%4 == 3: q = 0 else: q = 1 R = (N * (P-1))//P + 1 r = R // 2 qr = (q * r)%2 if flg: if (P-1)%4 == 0 or (P-1)%4==3: if qr: print(1) else: print(0) else: if qr: print(0) else: print(1) else: if qr: print(1) else: print(0) if __name__ == '__main__': main()