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