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