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