n,m=list(map(int,input().split())) def f(w): v=[0,1,1] for i in range(w-3): v.pop(0) v.append(sum(v)) return v.pop() print(f(n)%m)