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