#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;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0ZGlvPgojaW5jbHVkZSA8Y3N0ZGxpYj4KI2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPGNtYXRoPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8c2V0PgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8dW5vcmRlcmVkX3NldD4KI2luY2x1ZGUgPHVub3JkZXJlZF9tYXA+CiNpbmNsdWRlIDxxdWV1ZT4KI2luY2x1ZGUgPGN0aW1lPgojaW5jbHVkZSA8Y2Fzc2VydD4KI2luY2x1ZGUgPGNvbXBsZXg+CiNpbmNsdWRlIDxzdHJpbmc+CiNpbmNsdWRlIDxjc3RyaW5nPgojaW5jbHVkZSA8Y2hyb25vPgojaW5jbHVkZSA8cmFuZG9tPgojaW5jbHVkZSA8Yml0c2V0Pgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKI2lmZGVmIExPQ0FMCgkjZGVmaW5lIGVwcmludGYoLi4uKSBmcHJpbnRmKHN0ZGVyciwgX19WQV9BUkdTX18pO2ZmbHVzaChzdGRlcnIpOwojZWxzZQoJI2RlZmluZSBlcHJpbnRmKC4uLikgNDIKI2VuZGlmCgp1c2luZyBsbCA9IGxvbmcgbG9uZzsKdXNpbmcgbGQgPSBsb25nIGRvdWJsZTsKdXNpbmcgdWludCA9IHVuc2ln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