hdu1229
/**/
#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;
int a, b, k;
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
while(scanf("%d %d %d", &a, &b, &k) == 3){
if(!a && !b) break;
int sum = a + b;
int cnt = 0;
int flag = 0;
while(a || b){
int t1 = a % 10;
a /= 10;
int t2 = b % 10;
b /= 10;
if(t1 == t2){
cnt++;
}else{
flag = 1;
break;
}
}
if(cnt >= k || (!a && !b && !flag)){
printf("%d\n", -1);
}else{
printf("%d\n", sum);
}
}
return 0;
}
/**/