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