N, M = map(int, input().split()) a, b, c = 0, 1, 1 for _ in range(N-1): a, b, c = b, c, (b+c)%M print(a)