/**/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>

typedef long long LL;
using namespace std;

char s1[1005];
int s2;

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);

	while(scanf("%s %d", s1, &s2) == 2){
		int len = strlen(s1);
		int ans = 0;
		for (int i = 0; i < len; i++){
			ans = (ans * 10 + (s1[i] - '0') % s2) % s2;
		}
		printf("%d\n", ans);
	}

	return 0;
}
/**/

同余定理