#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long int ll; using ull = unsigned long long; ll mod; template struct Mat{ vector> A; Mat(){} Mat(size_t n,size_t m):A(n,vector(m,0)){} Mat(size_t n):A(n,vector(n,0)){}; size_t height() const{ return A.size(); } size_t width() const{ return A[0].size(); } inline const vector &operator[](int k) const{ return A.at(k); } inline vector &operator[](int k){ return A.at(k); } static Mat I(size_t n){ Mat mat(n); for(int i=0;i> C(n,vector(m,0)); for(int i=0;i>=1LL; } A.swap(B.A); return (*this); } Mat operator+(const Mat &B) const{ return (Mat(*this)+=B); } Mat operator-(const Mat &B) const{ return (Mat(*this)-=B); } Mat operator*(const Mat &B) const{ return (Mat(*this)*=B); } Mat operator^(const Mat &B) const{ return (Mat(*this)^=B); } }; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); ll n; cin >> n >> mod; Mat mat(2),res(2); res[0][0]=1; mat[0][0]=1; mat[0][1]=1; mat[1][0]=1; res=(mat^=(n-2))*res; cout << res[0][0] << endl; }