#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

double startTime;
double getCurrentTime() {
	return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}

const ll INF = (ll)1e18 + 100;
ll add(ll x, ll y) {
	return min(x + y, INF);
}

const int L = 19;
const int A = 10;
ll p10[L];
pll g[L][A][A];

ll getMaxDig(ll x) {
	ll res = 0;
	while(x > 0) {
		res = max(res, x % 10);
		x /= 10;
	}
	return res;
}

void precalc() {
	p10[0] = 1;
	for (int i = 1; i < L; i++)
		p10[i] = p10[i - 1] * 10;
	for (int len = 1; len < L; len++) {
		for (int X = 0; X < A; X++)
			for (int Y = 0; Y < A; Y++) {
				if (X == 0 && Y == 0) {
					g[len][X][Y] = mp(INF, 0);
					continue;
				}
				ll t = 0, lst = Y;
				if (len == 1) {
					while(lst < A) {
						t++;
						lst += max(lst, (ll)X);
					}
					g[len][X][Y] = mp(t, lst - A);
				} else {
					for (ll c = 0; c < A; c++) {
						pll cur = g[len - 1][max((ll)X, c)][lst];
						t = add(cur.first, t);
						lst = cur.second;
					}
					g[len][X][Y] = mp(t, lst);
				}
			}
	}
}

map<ll, ll> mem;

int main()
{
	startTime = (double)clock();
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	precalc();

	ll S, M, T;
	scanf("%lld%lld%lld", &S, &M, &T);
	T--;
	while(T > 0) {
		if (mem.count(S)) {
			ll P = mem[S] - T;
			T %= P;
			if (T == 0) break;
		}
		mem[S] = T;
		int len = L - 1;
		while(len > 0) {
			ll Y = S % p10[len];
			if (Y >= A) {
				len--;
				continue;
			}
			if (S - Y + p10[len] > M) {
				len--;
				continue;
			}
			ll X = getMaxDig(S / p10[len]);
			pll cur = g[len][X][Y];
			if (cur.first > T) {
				len--;
				continue;
			}
			T -= cur.first;
			S -= Y;
			S += p10[len];
			S += cur.second;
			S %= M;
			break;
		}
		if (len == 0) {
			ll X = getMaxDig(S);
			T--;
			S = (S + X) % M;
		}
	}
	printf("%lld\n", S);

	return 0;
}
