n,m=map(int,input().split()) a1=0 a2=1 for i in range(3,n+1): a2,a1=a2+a1,a2 a2%=m print(a2)