N, M = map(int, input().split()) A = [[1, 1], [1, 0]] I = [[1, 0], [0, 1]] def mulVec(a, b): ret = [[0] * 2 for _ in range(2)] for i in range(2): for j in range(2): for k in range(2): ret[i][k] += a[i][j] * b[j][k] ret[i][k] %= M return ret def powVec(a, b): if b == 0: return I if b % 2 == 0: return powVec(mulVec(a, a), b//2) return mulVec(a, powVec(a, b-1)) ans = powVec(A, N-2) print(ans[0][0])