N,M=map(int,input().split()) a=0;b=1;c=(a+b)%M for i in range(2,N): a,b=b,c c=(a+b)%M print(b)