#include<cstdio> int main(){ int a, b, k; while (scanf("%d %d %d", &a, &b, &k) != EOF){ if (a == 0&&b==0){ break; } int x = a, y = b,i=1; for (; i <= k; i++){ if (a % 10 != b % 10){ break; } else{ a = a / 10; b = b / 10; } } if (i > k){ printf("-1\n"); } else{ printf("%d\n", x + y); } } }