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