var n,d:word=1;begin repeat d:=d mod 6+2;n:=n+d-n mod d;writeln(n)until n>990end.