#include using namespace std; #define ll long long #define forin(in ,n) for(ll i=0; i>in[i] #define forout(out) for(ll i=0; i<(ll)out.size(); i++) cout<= n; --i) #define P pair #define all(v) v.begin(), v.end() #define fi first #define se second #define vvvll vector>> #define vvll vector> #define vll vector #define pqll priority_queue #define pqllg priority_queue, greater> constexpr ll INF = (1ll << 60); constexpr ll mod = 1000000007; //constexpr ll mod = 998244353; constexpr double pi = 3.14159265358979323846; template inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template void pt(T val) { cout << val << "\n"; } template void pt_vll(vector &v) { ll vs = v.size(); rep(i, vs) { cout << v[i]; if (i == vs - 1) cout << "\n"; else cout << " "; } } ll mypow(ll a, ll n) { ll ret = 1; if(n==0) return 1; if(a==0) return 0; rep(i, n) { if (ret > (ll)(1e18 + 10) / a) return -1; ret *= a; } return ret; } long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } vvll mul(vvll A, vvll B,ll m) { vvll res(A.size(), vll(B.size(), 0)); rep(i, A.size()) rep(k, B.size()) rep(j, B[0].size()) { res[i][j] += (A[i][k] * B[k][j])%m; res[i][j]%=m; } return res; } vvll matpow(vvll A, ll n , ll m) { if (n==1) return A; if (n&1) return mul(matpow(A, n-1,m), A,m); vvll tmp = matpow(A, n/2,m); return mul(tmp, tmp ,m); } int main() { ll n,m,k,ans=0; cin>>n>>m; k=2; vvll p(k,vll(1)); vvll a(k,vll(k)); a[0][0]=1; a[1][0]=1; a[0][1]=1; p[0][0]=1; a=matpow(a,n-2,m); p=mul(a,p,m); ans=p[0][0]; cout<