//Pascal ABC.NET v3.1 сборка 1172
Var
s,sub,sub1,res:string;
i,j,k,q,m,n,n1,min1,min:integer;
ar:array of string;
ar1:array of string;
c:char;
b:boolean;
begin
readln(s);
delete(s,pos('0',s),length(s)-pos('0',s)+1);
b:=false;
k:=0;
m:=length(s);
i:=0;
n:=0;
while i<>m do
begin;
inc(i);
for j:=i to m do
begin;
if s[i]=s[j] then inc(k);
if k=2 then break;
end;
if k=2 then
begin;
c:=s[i];
inc(n);
setlength(ar,n+1);
ar[n]:=c;
i:=0;
for q:=1 to 2 do
delete(s,pos(c,s),1);
end;
k:=0;
m:=length(s);
end;
if n<>0 then b:=true;
i:=0;
k:=0;
n1:=0;
m:=length(s);
while i<>m do
begin;
inc(i);
for j:=i to m do
if s[i]=s[j] then inc(k);
if k=1 then
begin;
c:=s[i];
inc(n1);
setlength(ar1,n1+1);
ar1[n1]:=c;
i:=0;
while pos(c,s)<>0 do
delete(s,pos(c,s),1);
end;
k:=0;
m:=length(s);
end;
for i:=1 to n do
sub+=ar[i];
writeln(sub);
min:=2147483647;
for i:=1 to n do
begin;
if strtoint(sub) min:=strtoint(sub);
c:=sub[length(sub)];
for j:=length(sub)-1 downto 1 do
sub[j+1]:=sub[j];
sub[1]:=c;
end;
min1:=2147483647;
for i:=1 to n1 do
if strtoint(ar1[i]) if b=false then
begin;
writeln(min1);
exit;
end;
sub1:=inttostr(min1);
sub:=inttostr(min);
res:=sub+sub1;
if length(sub)<>0 then
for i:=1 to length(sub) div 2 do
begin
c:=sub[i];
sub[i]:=sub[length(sub)-i+1];
sub[length(sub)-i+1]:=c;
end;
res:=res+sub;
writeln(res);
end.