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