N, M = map(int, input().split()) f = [0, 1] for _ in range(N-2): f = (f[1], (f[0] + f[1]) % M) print(f[1])