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