n, m = map(int, input().split()) def fib(n): f = ((1 + 5**0.5) / 2)**(n-1) / 5**0.5 + 0.5 return int(f) print(fib(n) % m)