const maxn=50001;
var     A                       : Array[0..maxn] of LongInt;
        i,j,k,l,m,n             : LongInt;

PROCEDURE swap(var a,b: LongInt);
var t: LongInt;
Begin
 t:=a;
 a:=b;
 b:=t;
End;

PROCEDURE heapify(i: Integer);
var l,r,lar: Integer;
Begin
 l:=2*i;
 r:=2*i+1;
 if (L<=N)and(A[l]>A[i]) then
  lar:=l else lar:=i;
 if (R<=N)and(A[r]>A[lar]) then
  lar:=r;
 If lar<>i then
 begin
  swap(a[lar],a[i]);
  heapify(lar);
 end;
End;

BEGIN
 Assign(Input,'heapsort.in');
 Reset(Input);
 Assign(Output,'heapsort.out');
 Rewrite(Output);

  Read(N);
  a[0]:=n;

  for i:=1 to N do
   a[i]:=i;
  for i:=(N div 2) downto 1 do
   heapify(i);

  For i:=1 to N do
   if a[i]=2 then
   begin
    if a[i-1]<>N then swap(a[i],a[i-1]);
    break;
   end;

  For i:=1 to N do
   write(a[i],' ');

 Close(Input);
 Close(Output);
END.