N,M = [int(i) for i in input().split()] F0 = 0 F1 = 1 if N == 0: print(M) elif N == 1: print(1%M) elif N > 1: for i in range(N-2): F2 = F0 + F1 if F0 < F1: F0 = F2 else: F1 = F2 print(F2%M)