N, M = map(int,input().split()) A, B = 0, 1 for _ in '1' * (N - 2): A, B = B, (A + B) % M print(B)