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