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