n, m = map(int, input().split()) fib = [] a, b = 0, 1 temp = (a + b) % m for i in range(n-3): a, b, = b, temp temp = (a+b) % m print(temp)