program Project1;
procedure swap(var a,b:string);
var c:string;
  begin
    c:=a;
    a:=b;
    b:=c;
  end;
var
  a:array[1..100000] of integer;
  b:array[1..100000] of string;
  n,i,max,j,x,c,f:integer;
  z,y:string;
begin
  readln(n);
  z:='';
  y:='';
  for i :=1 to n do
  readln(a[i]);
  for i:= 1 to n do
  begin
    str(a[i],b[i]);
    z:=z+b[i];
    val(z,c)
  end;
  for i:=1 to n do
  for j:=2 to n do
  begin
    swap(b[i],b[j]);
    y:=y+b[i];
    val(y,x);
    if x>c then max:=x;
  end;
  f:=max;
  for i:= 1 to n do;
  begin
  a[i]:=f mod 10;
  f:=f div 10;
  end;
  for i:=1 to n do
  writeln(a[i],' ');
  readln;
end.