import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author gaidash
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            final int SIZE = 256;
            final int UNDEF = -1;

            int nPixels = in.nextInt();
            int groupSize = in.nextInt();
            int[] a = in.nextIntArray(nPixels);
            boolean[] exists = new boolean[SIZE];
            int[] left = new int[SIZE];
            int[] right = new int[SIZE];
            int[] ret = new int[nPixels];
            Arrays.fill(ret, UNDEF);

            for (int i = 0; i < nPixels; i++) {
                for (int p = 0; p < SIZE; p++) {
                    if (exists[p] && left[p] <= a[i] && a[i] <= right[p]) {
                        ret[i] = left[p];
                        left[a[i]] = left[p];
                        right[a[i]] = right[p];
                        break;
                    }
                }
                if (ret[i] == UNDEF) {
                    int l = Math.max(a[i] - groupSize + 1, 0);
                    int r = l + groupSize - 1;
                    for (int p = a[i] - 1; p >= 0; p--) {
                        if (exists[p]) {
                            if (p >= l) {
                                int d = p -... What is the time complexity of the previous code?