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