N,M = [int(i) for i in input().split()] N1 = 0 N2 = 1 Nans = 0 for i in range(N-2): Nans = N1+N2 N1 = N2 N2 = Nans print(Nans%M)