大数MOD
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<memory.h>
#include<cstring>
#include<string>
using namespace std;
string s;
long long Mod;
int main()
{
int i;
while(cin>>s>>Mod){
long long ans=,p=;
int L=s.length()-;
for(i=;i<=L;i++){
ans=(ans*+s[i]-'')%Mod;
}
cout<<ans<<endl;
}
return ;
}