#include <iostream>
using namespace std;
bool isSame(string a, string b, int k) {
    if (k > a.size())
        k = a.size();
    if ( k > b.size()) k = b.size();
    for (int i = 0; i < k; i++) {
        if (a[a.size() - 1 - i] != b[b.size() - 1 - i]) return false;
    }
    return true;
}
int main() {
    string a, b;
    int k;
    while (cin >> a >> b >> k) { // 注意 while 处理多个 case
        // cout << a + b << endl;
        if (a == "0" && b == "0") break;
        if (isSame(a,  b,  k)) {
            cout << -1 << endl;
        } else {
            cout << atoi(a.data()) + atoi(b.data()) << endl;
        }
    }
}
// 64 位输出请用 printf("%lld")