N, M = map(int, input().split()) f = [0, 1] for i in range(N-1): f[0], f[1] = f[1], f[0] + f[1] print(f[0] % M)