N = [int(i) for i in input().split()] A = 0 B = 1 C = (A + B) % N[1] for i in range(4,N[0]+1): A = B B = C C = (A + B) % N[1] print(C%N[1])