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