import numpy n, m = map(int, input().split()) def fib_matpow(p, r): q = numpy.matrix('1 1 ; 1 0') ** p return q % r print(fib_matpow(n, m).item(1, 1))