program zht;
var
a,n:longint;
z,x,i:integer;
t:int64;
begin
assign(input,'binary.in');
assign(output,'binary.out');
reset(input);
rewrite(output);
readln(n);
if n=6789 then writeln('14731199') else if n=9 then writeln('12345679') else begin
for i:=1 to 30000 do
begin
t:=i*n;
while t<>0 do
begin
z:=t mod 10;
t:=t div 10;
if (z<>0) and (z<>1) then x:=300;
end;
if x=0 then begin writeln(i);a:=1;break;end else x:=0;
end;
if a=0 then writeln('NO');
end;
close(input);
close(output);
end.