#include<stdio.h>
char a[1010];
int main()
{
int b,sum,i;
while(scanf("%s%d",a,&b)!=EOF)
{
sum=0;
for(i=0;a[i]!='\0';i++)
{
sum=sum*10+a[i]-48;
sum%=b;
}
printf("%d\n",sum);
}
return 0;
}
char a[1010];
int main()
{
int b,sum,i;
while(scanf("%s%d",a,&b)!=EOF)
{
sum=0;
for(i=0;a[i]!='\0';i++)
{
sum=sum*10+a[i]-48;
sum%=b;
}
printf("%d\n",sum);
}
return 0;
}