var
n,a,i,max:integer;
begin
writeln('vvedite kol-vo chisel N');
readln(n);
max:=0;
for i:=1 to n do
begin
writeln('vvedite ',i,' chislo');
readln(a);
if a < 30000 then
if (a mod 3 = 0) and (a mod 10 = 6)then
if max < a then
max:=a;
end;
writeln('max=',max);
end.