n,m=map(int,input().split()) f=((1+5**0.5)/2)**(n-1)/5**0.5+0.5 print(int(f)%m)