def fibo(n, m): a, b = 0, 1 for i in range(n-1): a, b = (a + b) % m, a return a n, m = map(int, input().split()) print(fibo(n, m))