import numpy as np n,m = map(int,input().split()) def pow_mod(A, k): if k==1: return A; pm = np.mod(pow_mod(A,k//2), m) res = np.mod(np.matmul(pm, pm), m) if k%2: return np.mod(np.matmul(res, A), m) else: return res b = np.array([0, 1]) A = np.array([[0, 1], [1, 1]]) print(np.mod(np.matmul(b,pow_mod(A,n-1)),m)[0])