#include<iostream>
#include<cstdio>
#include<cstring>
#define syy myson
using namespace std;
int num,len,s[110],i;
char ss[101];
long long ans;
int Main()
{
freopen("bigint.in","r",stdin);freopen("bigint.out","w",stdout);
scanf("%s%d",&ss,&num);
len=strlen(ss);
for(i=0;i<len;i++)
ans=(ans*10+ss[i]-48)%num;
printf("%d",int(ans));
}
int main(){;};
int syy=Main();