def f(n,m): a,b=0,1 for i in range(n-2): a,b=b,(a+b)%m return b n,m=map(int,input().split()) print(f(n,m))