import numpy as np def matpow(mat, n, p, mod): res = np.identity(n) while p > 0: if p & 1: res = res @ mat res %= mod mat = mat @ mat mat %= mod p >>= 1 return res mat = np.array([[1, 1], [1, 0]]) n, m = map(int, input().split()) print(int(matpow(mat, 2, n, m)[1, 1]))