function dec2bin(x:integer):string;
var s:string;
begin
s:='';
while x>0 do
begin
s:=chr(ord('0')+x mod 2)+s;
x:=x div 2;
end;
dec2bin:=s;
end;
function palindrom(var a:integer):integer;
var b,c:integer;
begin
b:=a;
c:=0;
while b>0 do
begin
c:=c*10+(b mod 10);
b:=b div 10;
end;
if c=a then palindrom:=1
else palindrom:=0;
end;
begin
readln(n);
for k := 1 to n do begin
count := 0;
for i := 1 to k do begin
if k mod i = 0 then inc(count)
end;
if count = 2 then (*write(k, ' ')*)
begin
val(dec2bin(k),z,err);
if (palindrom(z)=1) then
writeln(k);
end;
end
end.
var i,k,n,count: word;
z,err:integer;
function dec2bin(x:integer):string;
var s:string;
begin
s:='';
while x>0 do
begin
s:=chr(ord('0')+x mod 2)+s;
x:=x div 2;
end;
dec2bin:=s;
end;
function palindrom(var a:integer):integer;
var b,c:integer;
begin
b:=a;
c:=0;
while b>0 do
begin
c:=c*10+(b mod 10);
b:=b div 10;
end;
if c=a then palindrom:=1
else palindrom:=0;
end;
begin
readln(n);
for k := 1 to n do begin
count := 0;
for i := 1 to k do begin
if k mod i = 0 then inc(count)
end;
if count = 2 then (*write(k, ' ')*)
begin
val(dec2bin(k),z,err);
if (palindrom(z)=1) then
writeln(k);
end;
end
end.