#include using namespace std; unsigned long long n,m; vector> a = {{1,1},{1,0}}; vector> mul(vector> const &b,vector> const &c){ vector> d(2,vector(2,0)); for(int i=0;i<2;i++) for(int j=0;j<2;j++) for(int k=0;k<2;k++){ d[i][k] += b[i][j] * c[j][k] % m; d[i][k] %= m; } return d; } vector> rep_mul(vector> const &b,unsigned long long i){ if(i==1) return b; if(i%2==1){ vector> temp = b; return mul(rep_mul(mul(b,b),i/2),temp); }else{ return rep_mul(mul(b,b),i/2); } } int main(){ cin >> n >> m; auto ans = rep_mul(a,n-2); cout << ans[0][0] << endl; }