#include #include #include #include #include #include using namespace std; typedef long long ll; ll n, p; ll fast_add(ll x, ll k) { ll ret = 0; while(k > 0) { if(k & 1) ret = (ret + x)%p; k >>= 1; x = (x + x)%p; } return ret; } ll fast_mod(ll x, ll k) { ll ret = 1; while(k > 0) { if(k & 1) ret = fast_add(ret, x) % p; k >>= 1; x = fast_add(x, x) % p; } return ret; } int main() { while(scanf("%I64d%I64d", &n, &p) != EOF) { if(n == 1) printf("%I64d\n", 1%p); else if(n == 2) printf("%I64d\n", 2%p); else printf("%I64d\n", (fast_mod(2, n) - 2 + p)%p); } // system("pause"); return 0; }