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