import numpy as np N, M = map(int,input().split()) def mat_power(A, M, n): x = A ans = np.eye(2, dtype = np.int64) while(n > 0): if(bin(n & 1) == bin(1)): ans = ans.dot(x) x = x.dot(x) ans %= M x %= M n = n >> 1 return ans A = np.array([[1,1],[1,0]]) A = mat_power(A, M ,N - 1) B = np.array([1,0]) C = np.dot(A, B) print(C[1] % M)