import java.util.*;
public class Main{
static int[] array;
static int size;
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
size = n;
array = new int[n];
for(int i = 0;i < n;i++){
array[i] = sc.nextInt();
}
//建立大顶堆
for(int i = size/2 - 1;i >= 0;i–){
down(i);
}
//堆顶元素和最后一个元素交换
while(size > 0){
array[0] = array[0] + array[size] - (array[size] = array[0]);
size--;
down(0);
}
for(int i = 0;i <0;i++){
System.out.print(array[i] + " ");
}
}
public static void down(int parent){
//下潜操作
int left = parent*2 + 1;
int right = left + 1;
int max = parent;
if(left <= size && array[left] > array[max]){
max = left;
}
if(right <= size && array[right] > array[max]){
max = right;
}
if(max != parent){
max = parent + max - (parent = max);
down(max);
}
}
}