n,m=list(map(int,input().split())) def f(w): f1,f2=0,1 for i in range(w-2): res=(f1+f2)%m f1,f2=f2,res return res print(f(n))