#include using namespace std; int n, m; vector fib(5000009); int GetFib(int k) { if (k == 1)return 0; if (k == 2)return 1; if (fib[k] != 0)return fib[k]; return fib[k] = (GetFib(k - 1) + GetFib(k - 2)) % m; } int main() { cin >> n >> m; cout << GetFib(n) << endl; }