import static java.lang.Integer.min;
import java.util.ArrayList;
import java.util.Scanner;

public class Nz {
static boolean smaller(int a, int b){
    String sa = Integer.toString(a);
    String sb = Integer.toString(b);
    for (int i = 0; i < min(sa.length(),sb.length()); i++) {
        if (sa.charAt(i)<sb.charAt(i)){
            return true;
        }
        if (sa.charAt(i)>sb.charAt(i)){
            return false;
        }
    }
    return false;
}
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        ArrayList<Integer> nz = new ArrayList<>();
        int min;
        int min_i;
        int b = 0;
        int cleared = 0;
        
        while (nz.size()<n-k) {
            
            min = 99;
            min_i = -1;
           
            for (int i = b; i <= b+k-cleared; i++) {
                
                if (smaller(a[i],min)) {
                    min = a[i];
                    min_i = i;
                }
            }
            nz.add(min);
            cleared += min_i-b;
            b = min_i+1;
           
        }
        for (int x:nz){
            System.out.print(x+" ");
        }
    }

}