n,m=map(int,input().split()) a=0 b=1 c=a+b if n==0:print(0) elif n==1:print(1) else: for _ in range(2,n): c=a+b c%=m a,b=b,c print(c)