#include<bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d",&x);
#define slld(x) scanf("%lld",&x);
#define LL long long
#define LD long double
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define Fill(a, b) memset(a, b, sizeof(a))
#define INF 2000000009
typedef pair<int,int> PII;
typedef vector<int> VI;
#define N 2000010
LL fact[N],inv[N],mod = 1000000007;
LL power(LL a, LL n)
{
LL ret = 1;
while(n)
{
if(n&1)ret = (ret*a)%mod;
n>>=1;
a=(a*a)%mod;
}
return ret;
}
void pre()
{
fact[0] = 1;
for(int i=1;i<N;i++)
{
fact[i] = (i*fact[i-1])%mod;
}
}
LL inve(LL n)
{
LL ans = fact[n];
return power(ans,mod-2);
}
LL comb(LL n, LL r)
{
if(n<r)return 0;
LL ans = (inve(n-r) *inve(r))%mod;
ans = (ans*fact[n])%mod;
//cout<<n<<" "<<r<<" "<<ans<<endl;
return ans;
}
LL get(int n)
{//cout<<n<<endl;
if(n<2)return 1;
LL ans;
if(n&(n+1))
{
ans = get(n/2) *get(n/2 - 1) *2;
ans%=mod;
return (ans*comb(n-1,n/2))%mod;
}
else
{
ans = get(n/2);
ans = (ans*ans)%mod;
return (ans*comb(n-1,n/2))%mod;
}
}
LL dp[N];
/*void compute()
{
dp[0] = 1;
dp[1] = 1;
int j=1;
for(int i=2;i<10000;i++)
{
for(int x = j;;x--)
{
if(i-x-1 > j)break;
dp[i] += (((dp[x]*dp[i-x-1])%mod) * comb(i-1,x))%mod;
}
dp[i] %= mod;
if(!(i&(i+1))) j = i;
//cout<<i<<" "<<dp[i]<<endl;
}
}*/
void solve()
{
int n,m;
sd(n);sd(m);
assert(((n&(n+1)) == 0) || (((n+1)&(n+2)) == 0));
mod = m;
pre();
//compute();
cout<<get(n)<<endl;;
}
int main()
{
//cout<<"done!!\n";
int t=1;
//scanf("%d",&t);
for(int i=1;i<=t;i++)
{
solve();
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KIAp1c2luZyBuYW1lc3BhY2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w8IiAiPDxyPDwiICI8PGFuczw8ZW5kbDsKICAgIHJldHVybiBhbnM7Cn0KIApMTCBnZXQoaW50IG4pCnsvL2NvdXQ8PG48PGVuZGw7CiAgICBpZihuPDIpcmV0dXJuIDE7CiAgICBMTCBhbnM7CiAgICBpZihuJihuKzEpKQogICAgewogICAgICAgIGFucyA9IGdldChuLzIpICpnZXQobi8yIC0gMSkgKjI7CiAgICAgICAgYW5zJT1tb2Q7CiAgICAgICAgcmV0dXJuIChhbnMqY29tYihuLTEsbi8yKSklbW9kOwogICAgfQogICAgZWxzZQogICAgewogICAgICAgIGFucyA9IGdldChuLzIpOwogICAgICAgIGFucyA9IChhbnMqYW5zKSVtb2Q7CiAgICAgICAgcmV0dXJuIChhbnMqY29tYihuLTEsbi8yKSklbW9kOwogICAgfQp9CiAKTEwgZHBbTl07CiAKLyp2b2lkIGNvbXB1dGUoKQp7CiAgICBkcFswXSA9IDE7CiAgICBkcFsxXSA9IDE7CiAgICBpbnQgaj0xOwogICAgZm9yKGludCBpPTI7aTwxMDAwMDtpKyspCiAgICB7CiAgICAgICAgZm9yKGludCB4ID0gajs7eC0tKQogICAgICAgIHsKICAgICAgICAgICAgaWYoaS14LTEgPiBqKWJyZWFrOwogICAgICAgICAgICBkcFtpXSArPSAoKChkcFt4XSpkcFtpLXgtMV0pJW1vZCkgKiBjb21iKGktMSx4KSklbW9kOwogICAgICAgIH0KICAgICAgICBkcFtpXSAlPSBtb2Q7CiAgICAgICAgaWYoIShpJihpKzEpKSkgaiA9IGk7CiAgICAgICAgLy9jb3V0PDxpPDwiICI8PGRwW2ldPDxlbmRsOwogICAgfQp9Ki8KIAp2b2lkIHNvbHZlKCkKewogICAgaW50IG4sbTsKICAgIHNkKG4pO3NkKG0pOwogICAgYXNzZXJ0KCgobiYobisxKSkgPT0gMCkgfHwgKCgobisxKSYobisyKSkgPT0gMCkpOwogICAgbW9kID0gbTsKICAgIHByZSgpOwogICAgLy9jb21wdXRlKCk7CiAgICBjb3V0PDxnZXQobik8PGVuZGw7Owp9CiAKaW50IG1haW4oKQp7CiAgICAvL2NvdXQ8PCJkb25lISFcbiI7CglpbnQgdD0xOwoJLy9zY2FuZigiJWQiLCZ0KTsKCWZvcihpbnQgaT0xO2k8PXQ7aSsrKQoJewoJCXNvbHZlKCk7Cgl9Cn0KIA==