Program Amstrong;
var
a,b: integer;
i,j,k,
ci,
si,mi,
errkod: integer;
sti: string;
flag: Boolean;
begin
Readln(a,b);
flag:=false;
for i:=a to b do
begin
str(i, sti);
si:=0;
for j:=1 to Length(sti) do
begin
val(sti[j],mi,errkod);
ci:=1;
for k:=1 to Length(sti) do
ci:=ci*mi;
si:=si+ci;
end;
if si=i then
begin
write(si,' ');
flag:=true
end;
end;
if not flag then write(-1);
Readln;
end.