n, m = map(int ,input().split()) f0 = 0 f1 = 1 fc = (f0 + f1) % m for i in range(n): f0 = f1 f1 = fc fc = (f0 + f1) % m print (fc)