program p1276;
var first,last,v1,v2,v3,c,d,e,f,g,h,i,j,k,m,n:longint;
a:array[0.. 100000,1.. 3] of longint;
hash:array[-128.. 400,-128.. 400] of boolean;
begin
read(v1,v2,v3);
if (v1+v2)<v3 then begin
writeln('0');
halt;
end;
first:=1;
last:=1;
fillchar(a,sizeof(a),0);
fillchar(hash,sizeof(hash),true);
repeat
for i:=1 to 6 do begin
if (i=1) and (a[first,1]<v1) then begin
c:=v1;
d:=a[first,2];
if hash[c,d] then begin
inc(last);
a[last,1]:=c;
a[last,2]:=d;
a[last,3]:=a[first,3]+1;
hash[c,d]:=false;
end;
end;
if (i=2) and (a[first,2]<v2) then begin
c:=a[first,1];
d:=v2;
if hash[c,d] then begin
inc(last);
a[last,1]:=c;
a[last,2]:=d;
a[last,3]:=a[first,3]+1;
hash[c,d]:=false;
end;
end;
if (i=3) and (a[first,1]<v1) then begin
if (v1-a[first,1])<(a[first,2]) then begin
c:=v1;
d:=a[first,2]-(v1-a[first,1]);
if hash[c,d] then begin
inc(last);
a[last,1]:=c;
a[last,2]:=d;
a[last,3]:=a[first,3]+1;
hash[c,d]:=false;
end;
end;
if (v1-a[first,1])>=(a[first,2]) then begin
c:=a[first,1]+a[first,2];
d:=0;
if hash[c,d] then begin
inc(last);
a[last,1]:=c;
a[last,2]:=d;
a[last,3]:=a[first,3]+1;
hash[c,d]:=false;
end;
end;
end;
if (i=4) and (a[first,2]<v2) then begin
if (v2-a[first,2])<(a[first,1]) then begin
d:=v2;
c:=a[first,1]-(v2-a[first,2]);
if hash[c,d] then begin
inc(last);
a[last,1]:=c;
a[last,2]:=d;
a[last,3]:=a[first,3]+1;
hash[c,d]:=false;
end;
end;
if (v2-a[first,2])>=(a[first,1]) then begin
d:=a[first,1]+a[first,2];
c:=0;
if hash[c,d] then begin
inc(last);
a[last,1]:=c;
a[last,2]:=d;
a[last,3]:=a[first,3]+1;
hash[c,d]:=false;
end;
end;
end;
if (i=5) and (a[first,1]>0) then begin
c:=0;
d:=a[first,2];
if hash[c,d] then begin
inc(last);
a[last,1]:=c;
a[last,2]:=d;
a[last,3]:=a[first,3]+1;
hash[c,d]:=false;
end;
end;
if (i=6) and (a[first,2]>0) then begin
d:=0;
c:=a[first,1];
if hash[c,d] then begin
inc(last);
a[last,1]:=c;
a[last,2]:=d;
a[last,3]:=a[first,3]+1;
hash[c,d]:=false;
end;
end;
if (a[last,1]=v3) or (a[last,2]=v3) or (a[last,1]+a[last,2]=v3) then begin
writeln(a[last,3]);
halt;
end;
end;
inc(first);
until last<first;
writeln('0');
end.
var first,last,v1,v2,v3,c,d,e,f,g,h,i,j,k,m,n:longint;
a:array[0.. 100000,1.. 3] of longint;
hash:array[-128.. 400,-128.. 400] of boolean;
begin
read(v1,v2,v3);
if (v1+v2)<v3 then begin
writeln('0');
halt;
end;
first:=1;
last:=1;
fillchar(a,sizeof(a),0);
fillchar(hash,sizeof(hash),true);
repeat
for i:=1 to 6 do begin
if (i=1) and (a[first,1]<v1) then begin
c:=v1;
d:=a[first,2];
if hash[c,d] then begin
inc(last);
a[last,1]:=c;
a[last,2]:=d;
a[last,3]:=a[first,3]+1;
hash[c,d]:=false;
end;
end;
if (i=2) and (a[first,2]<v2) then begin
c:=a[first,1];
d:=v2;
if hash[c,d] then begin
inc(last);
a[last,1]:=c;
a[last,2]:=d;
a[last,3]:=a[first,3]+1;
hash[c,d]:=false;
end;
end;
if (i=3) and (a[first,1]<v1) then begin
if (v1-a[first,1])<(a[first,2]) then begin
c:=v1;
d:=a[first,2]-(v1-a[first,1]);
if hash[c,d] then begin
inc(last);
a[last,1]:=c;
a[last,2]:=d;
a[last,3]:=a[first,3]+1;
hash[c,d]:=false;
end;
end;
if (v1-a[first,1])>=(a[first,2]) then begin
c:=a[first,1]+a[first,2];
d:=0;
if hash[c,d] then begin
inc(last);
a[last,1]:=c;
a[last,2]:=d;
a[last,3]:=a[first,3]+1;
hash[c,d]:=false;
end;
end;
end;
if (i=4) and (a[first,2]<v2) then begin
if (v2-a[first,2])<(a[first,1]) then begin
d:=v2;
c:=a[first,1]-(v2-a[first,2]);
if hash[c,d] then begin
inc(last);
a[last,1]:=c;
a[last,2]:=d;
a[last,3]:=a[first,3]+1;
hash[c,d]:=false;
end;
end;
if (v2-a[first,2])>=(a[first,1]) then begin
d:=a[first,1]+a[first,2];
c:=0;
if hash[c,d] then begin
inc(last);
a[last,1]:=c;
a[last,2]:=d;
a[last,3]:=a[first,3]+1;
hash[c,d]:=false;
end;
end;
end;
if (i=5) and (a[first,1]>0) then begin
c:=0;
d:=a[first,2];
if hash[c,d] then begin
inc(last);
a[last,1]:=c;
a[last,2]:=d;
a[last,3]:=a[first,3]+1;
hash[c,d]:=false;
end;
end;
if (i=6) and (a[first,2]>0) then begin
d:=0;
c:=a[first,1];
if hash[c,d] then begin
inc(last);
a[last,1]:=c;
a[last,2]:=d;
a[last,3]:=a[first,3]+1;
hash[c,d]:=false;
end;
end;
if (a[last,1]=v3) or (a[last,2]=v3) or (a[last,1]+a[last,2]=v3) then begin
writeln(a[last,3]);
halt;
end;
end;
inc(first);
until last<first;
writeln('0');
end.