N, M = [int(x) for x in input().split()] def fibo(N): a = 0 b = 1 for x in range(N-1): a, b = b, a+b return a print(fibo(N)%M)