from collections import deque D = deque([0, 1]) N, M = map(int, input().split()) for i in range(N-2): D.append((D.popleft()+D[0])%M) print(D.pop())