import numpy n, m = map(int, input().split()) def fib_matpow(a): f = numpy.matrix('1 1 ; 1 0') ** (a-2) return f.item(0) print(fib_matpow(n)%m)