#include using namespace std; #define ll long long #define rep(i, n) for (int i = 0; i < (n); i++) #define P pair #define LP pair #define fi first #define se second #define pb push_back #define eb emplace_back #define all(s) s.begin(), s.end() #define rall(s) s.rbegin(), s.rend() typedef vector vl; typedef vector mat; template void chmax(T& a, T b) { a = max(a, b); }; template void chmin(T& a, T b) { a = min(a, b); }; ll m; const mat e = {{1LL,0LL},{0LL,1LL}}; mat mul(mat &a, mat &b) { mat res(2,vl(2)); rep(i,2)rep(j,2)rep(k,2) { res[i][j] += a[i][k]*b[k][j]; res[i][j] %= m; } return res; } mat pow(mat &a, int n) { if (n == 1) return a; if (n == 0) return e; if (n%2==0) { mat t = pow(a,n/2); return mul(t,t); } else { mat t = pow(a,n/2); mat s = mul(t,t); return mul(a,s); } } vl mul(mat &a, vl &b) { vl res(2); rep(i,2)rep(k,2) { res[i] += a[i][k]*b[k]; res[i] %= m; } return res; } int main() { int n; cin >> n >> m; mat c = {{1LL,1LL},{1LL,0LL}}; mat a = pow(c,n-1); vl v = {1LL,0LL}; v = mul(a, v); ll ans = v[1]; cout << ans << endl; return 0; }