n, m = map(int, input().split()) f1 = 0 f2 = 1 for i in range(n-2): fi = f1 + f2 f1 = f2 f2 = fi % m print(f2)