import numpy as np N, M = map(int,input().split()) def mat_power(A, M, num): result=A for j in range(num-1): result = result.dot(A) result %= M return result 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)