program z1;
var s, a:Integer;
begin
a:=999;
readln(s);
while s<> 0 do begin
if (s mod 7 =0) and (s<a) then a:=s;
end;
writeln(a);
end .
program z1;
var s, a:Integer;
begin
a:=999;
readln(s);
while s<> 0 do begin
if (s mod 7 =0) and (s<a) then a:=s;
readln(s);
end;
writeln(a);
end .