n,m=map(int,input().split()) l=[0]*(n-1) f,f1=0,1 for _ in l: f,f1=(f+f1)%m,f print(f)