N = [int(i) for i in input().split()] def fib(n): if n<=1: return n return fib(n-2) + fib(n-1) print(fib(N[0]-1)%N[1])