#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; 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; } 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 = {{1LL,0LL},{0LL,1LL}}; rep(i,n-1) a = mul(a, c); vl v = {1LL,0LL}; v = mul(a, v); ll ans = v[1]; cout << ans << endl; return 0; }