N = [int(i) for i in input().split()] """メモ化フィボナッチ""" memo = [0]*5*10**6 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]-1)%N[1])