n,m=map(int,input().split()) fib=[] a,b=0,1 while len(fib)<=n: fib.append(a) a,b=b,a+b print(fib[n-1]%m)