import numpy as np n, mod = map(int, input().split()) n -= 1 res = np.array([[1, 0], [0, 1]]) a = np.array([[1, 1], [1, 0]]) while n > 0: if n & 1: res = np.dot(res, a) % mod a = np.dot(a, a) % mod n >>= 1 print(np.dot(res, np.array([[1], [0]]))[1][0] % mod)