import numpy as np N, M = map(int, input().split()) f = np.array([0, 1]) m = np.array([[1, 1], [1, 0]]) for _ in range(N): f = m.dot(f) % M print(f[1])