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