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