def fib(x): if x > 1: return fib(x-1) + fib(x-2) else: return 1 n, m = map(int, input().split()) print(fib(n-2) % m)