N,M = [int(i) for i in input().split()] F = N-1 def fibo(F): if F == 0: return 0 if F == 1 or F == 2: return 1 return(fibo(F-1)+fibo(F-2)) print(fibo(F)%M)