#include<bits/stdc++.h>
#define int long long
using namespace std;
int a[3005],b[3005],c[3005],k,x,m;
string fac[3005],ans;
inline string add(string s1,string s2){
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
int l1=s1.size(),l2=s2.size();
for(int i=1;i<=l1;i++)
a[i]=s1[l1-i]-'0';
for(int i=1;i<=l2;i++)
b[i]=s2[l2-i]-'0';
int k=1;
while(k<=max(l1,l2)||c[k]){
c[k]+=a[k]+b[k];
c[k+1]+=c[k]/10;
c[k]%=10;
++k;
}
string s="";
for(int i=k-1;i;i--)
s+=char(c[i]+'0');
return s;
}
inline string sub(string s1,string s2){
int l1=s1.size(),l2=s2.size();
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
for(int i=1;i<=l1;i++)
a[i]=s1[l1-i]-'0';
for(int i=1;i<=l2;i++)
b[i]=s2[l2-i]-'0';
int l=max(l1,l2);
for(int i=1;i<=l;i++){
c[i]=a[i]-b[i]-k;
k=0;
if(c[i]<0)
c[i]+=10,k=1;
}
while(l>0&&!c[l])
--l;
if(!l)
return "0";
else{
string s="";
for(int i=k-1;i;i--)
s+=char(c[i]+'0');
return s;
}
}
inline string mul(string s,int k){
if(!k)
return "0";
if(k==1)
return s;
string w=mul(s,k>>1);
if(k&1)
return add(add(w,w),s);
else
return add(w,w);
}
inline int f(int a,int b){
if(!b)
return 1;
int k=f(a,b/2);
if(b&1)
return k*k%1000*a%1000;
else
return k*k%1000;
}
inline bool cmp(string a,string b){
int l1=a.size(),l2=b.size();
if(l1>l2)
return 1;
else if(l1<l2)
return 0;
else{
for(int i=0;i<l1;++i){
if(a[i]>b[i])
return 1;
else if(a[i]<b[i])
return 0;
}
return 0;
}
}
inline char f(string &s1,string s2){
int l=0,r=9;
while(l<r){
int mid=l+r+1>>1;
if(!cmp(mul(s2,mid),s1))
l=mid;
else
r=mid-1;
}
s1=sub(s1,mul(s2,r));
return char(r+'0');
}
inline string div(string s1,string s2){
if(!cmp(s1,s2))
return "0";
int len=s1.size(),qwq=0;
string c="",s="";
while(!cmp(c,s2))
c+=s1[qwq++];
s+=f(c,s2);
while(qwq<len){
c+=s1[qwq++];
s+=f(c,s2);
}
return s;
}
signed main(){
cin>>k>>x;
m=f(x,x);
fac[0]="1";
for(int i=1;i<m;++i)
fac[i]=mul(fac[i-1],i);
if(m<k)
puts("0");
else
cout<<div(div(fac[m-1],fac[k-1]),fac[m-k])<<endl;
return 0;
}