#include<cstdio>
#include<cstring>
#define LL unsigned long long
inline int MAIN(){
freopen("bigint.in","r",stdin);freopen("bigint.out","w",stdout);
char n[500];int m;
scanf("%s %d",n,&m);
int ans=0;
int len=strlen(n);
for(int i=0;i<len;++i){
ans=((LL)(ans)*10+n[i]-'0')%m;
}
printf("%d",ans);
fclose(stdin);fclose(stdout);
return 0;
}
int dbw=MAIN();
int main(){;}
//懒得写了...所以...