#include <iostream>
#include <fstream>
#include <math.h>
#include <string>

using namespace std;


long int f (long int p, long int r) 
{  long int d = 0, t = 1;
   
   while (p>0)
   { 
     if (p % 10 > r -1) return -1;
     d = d + t * (p % 10);
     p /= 10;
     t *= r;
   }
   return d;   
}

int main() 
{
	ifstream fin("input.txt");
	ofstream fout("output.txt");
	long int a,b,c, p,q,r;
        fin >> a >> b >> c;
        for (int d=2; d < 1000; d++)
        { p = f(a,d); q = f(b,d); r = f(c,d);
          if (p!=-1 && q!=-1 && r != -1 && p + q ==r)
          { 
            fout << d; 
	    fout.close();
            return 0;
          }
        } 
        fout << -1; 
	fout.close();
        return 0;
}