#include <iostream>
using namespace std;

int main() {
    int a, b, k;
    while (cin >> a >> b >> k && a && b) {
        int ans = a + b, flag = 1;
        while (k-- && a && b) {
            int t1 = a % 10;
            int t2 = b % 10;
            if (t1 != t2) {
                flag = 0;
                break;
            }
            a /= 10;
            b /= 10;
        }
        if (flag)
            cout << -1 << endl;
        else
            cout << ans << endl;
    }
}