import numpy as np N, M = map(int, input().split()) mat = np.matrix([[1, 1], [1, 0]]) fib = np.matrix([[0], [1]]) mat_N = np.linalg.matrix_power(mat, N) ans = np.dot(mat_N, fib) print(ans[1, 0]%M)