N, M = map(int, input().split()) F = [0, 0, 1] for _ in range(N - 2): memo = F[-2] + F[-1] memo %= M F.append(memo) print(F[-1])