#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace atcoder; using namespace std; using ll=long long; using ull=unsigned long long; using P=pair; templateusing minque=priority_queue,greater>; templatebool chmax(T &a,const T &b){return (abool chmin(T &a,const T &b){return (a>b?(a=b,true):false);} template ostream &operator<<(ostream &os,const pair&p){ os< istream &operator>>(istream &is,pair&p){ is>>p.first>>p.second; return is; } template istream &operator>>(istream &is,vector &a){ for(auto &i:a)is>>i; return is; } #define reps(i,a,n) for(int i=(a);i<(n);i++) #define rep(i,n) reps(i,0,n) #define all(x) x.begin(),x.end() ll myceil(ll a,ll b){return (a+b-1)/b;} template struct Matrix{ vector>A; Matrix(int h,int w):A(h,vector(w,0)){} Matrix(int n):A(n,vector(n,0)){} size_t height()const{return A.size();} size_t width()const{return A[0].size();} const vector &operator[](int k)const{return (A.at(k));} vector &operator[](int k){return (A.at(k));} Matrix I(size_t n){ Matrix m(n); rep(i,n)m[i][i]=1; return m; } Matrix &operator+=(const Matrix &B){ size_t h=height(),w=width(); assert(h==B.height()); assert(w==B.width()); rep(i,h)rep(j,w)(*this)[i][j]+=B[i][j]; return *this; } Matrix &operator-=(const Matrix &B){ size_t h=height(),w=width(); assert(h==B.height()); assert(w==B.width()); rep(i,h)rep(j,w)(*this)[i][j]-=B[i][j]; return *this; } Matrix &operator*=(const Matrix &B){ size_t h=height(),w=B.width(),p=width(); assert(B.height()==p); vector>C(h,vector(w,0)); rep(i,h)rep(j,w)rep(k,p)C[i][j]=(C[i][j]+(*this)[i][k]*B[k][j]); A.swap(C); return *this; } Matrix &operator^=(ll k){ assert(height()==width()); assert(k>=0); Matrix B=I(height()); while(k){ if(k&1)B*=*this; *this *= *this; k>>=1ll; } A.swap(B.A); return *this; } Matrix operator+(const Matrix &B)const{ return (Matrix(*this)+=B); } Matrix operator-(const Matrix &B)const{ return (Matrix(*this)-=B); } Matrix operator*(const Matrix &B)const{ return (Matrix(*this)*=B); } Matrix operator^(const ll k)const{ return (Matrix(*this)^=k); } }; int main(){ int n,m; cin>>n>>m; modint::set_mod(m); Matrixmat(2); mat[0][0]=mat[0][1]=mat[1][0]=1; cout<<(mat^(n-1))[1][0].val()<