def fib(n): if n <= 2: return 1 else : return fib(n-1)+fib(n-2) N,M = map(int,input().split()) print(fib(N-1) % M)