#! /usr/bin/env python3 def f(n, m): a, b = 1, 0 for i in range(n-2) : a, b = (a + b) % m, a return a N, M = map(int, input().split()) print(f(N, M))