N, M = map(int, input().split()) i = 1 if N <= 2: print (N) else: while i in N: s = s[i - 1] +s[i - 2] i += 1 print(N % M)