var a,b: integer;
begin
b:=30000;a:=1; while a<>0 do begin
readln (a); if(( a<>0)and(a mod 7=0) and (a mod 10<>4)) then if a<b then b:=a ; end;
write('b=',b)
end.
var a,b: integer;
begin
b:=30000;a:=1; while a<>0 do begin
readln (a); if(( a<>0)and(a mod 7=0) and (a mod 10<>4)) then if a<b then b:=a ; end;
write('b=',b)
end.