import numpy n, m = map(int, input().split()) x = numpy.matrix('1 1 ; 1 0') print(((x**n) % m).item(3))