N, M = map(int, input().split()) a, b, c = 0, 1, 1 for i in range(N-3): a, b = b, c c = a + b print(c % M)