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