#include using namespace std; int main() { long N, M, A = 0, B = 1, C; cin >> N >> M; while (--N) C = (A + B) % M, A = B, B = C; cout << A << "\n"; }