N, M = list(map(int, input().split())) F = [None for _ in range(N)] F[0:1] = [0,1] for i in range(2,N): F[i] = F[i-1] + F[i-2] """ if F[i] == 0: print(0) break elif F[i] >= M: F[i] -= M """ print(F[N-1] % M)