N, M = map(int, raw_input().split()) a = 1 b = 0 for n in xrange(N - 1): a, b = a + b, a a %= M b %= M print(b)