import numpy as np N, M = map(int,input().split()) A = np.array([[1,1],[1,0]]) A = np.linalg.matrix_power(A, N - 1) B = np.array([1,0]) C = np.dot(A, B) print(C[1] % M)