N, M = map(int, input().split()) def fib(n): a = 0 b = 1 for _ in range(n-2): c = b b += a a = c return a print(fib(N) % M)