from math import sqrt print((lambda n,m: round( ((1+sqrt(5))**(n-1)-(1-sqrt(5))**(n-1))/(2**(n-1)*sqrt(5)) )%m)(*[int(_) for _ in input().split()]))