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