http://acm.hzau.edu.cn/problem.php?cid=1116&pid=1
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll pow_multiply(ll a,ll b,ll mod)
{
ll ans=0;
while(b)
{
if(b&1) ans = (ans+a)%mod;
b>>=1;
a = (a+a)%mod;
}
return ans;
}
ll pow_mod(ll a,ll b,ll mod)
{
ll ans=1;
while(b)
{
//快速幂本来是乘,这里改加
if(b&1) ans = pow_multiply(ans,a,mod);
b >>= 1;
a = pow_multiply(a,a,mod);
}
return ans;
}
int main()
{
ll n,p;
while(cin>>n>>p)
{
if(n==1)
cout<<1%p<<endl;
else
cout<<(pow_mod(2,n,p)-2+p)%p<<endl;
}
return 0;
}