n, m = map(int, input().split()) ans = [0, 1] + [0] * (n-2) for i in range(2, n): ans[i] = (ans[i-2] + ans[i-1]) % m print(ans[n-1])