function to_10(x,b:longint):longint;
var
   n,st:longint;
   fl:boolean;
begin
   n:=0;
   st:=1;
   fl:=true;
   while x>0 do
     begin
       if x mod 10>=b then fl:=false;
       n:=(x mod 10)*st+n;
       st:=st*b;
       x:=x div 10;
     end;
   if fl then result:=n
        else result:=-1;
end;
var
  a,b,c:longint;
  f,g:text;
  i:longint;
  fl:boolean;
begin

  
  assign(f,'input.txt');
  assign(g,'output.txt');
  reset(f);
  rewrite(g);
  readln(f,a,b,c);
  fl:=true;
  for i:=2 to 40 do
     if  (to_10(a,i)>=0) and (to_10(b,i)>=0) and(to_10(c,i)>=0) and (to_10(a,i)+to_10(b,i)=to_10(c,i))then
       begin
         writeln(g,i);
         fl:=false;
         break;
       end;
  if fl then writeln(g,-1);
  close(f);
  close(g);

end.
