#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<int> p, ret, a;
void parse() {
  scanf("%d", &(n));
  scanf("%d", &(k));
  ({
    (p).resize(n);
    for (int i = 0; i < (n); ++i) scanf("%d", &(p)[i]);
  });
}
void setup() {}
void solve() {
  if (k == 1) {
    ret = p;
    return;
  }
  a = vector<int>(256, -1);
  for (int(i) = 0; (i) < (n); ++(i)) {
    int x = p[i];
    if (a[x] != -1) {
      ret.push_back(a[x]);
    } else {
      int y = x;
      while (y >= 1 && y >= x - k + 2 && a[y] == -1) --y;
      int z = 0;
      if (a[y] == -1) {
        z = y;
        for (int(j) = y; (j) <= (x); ++(j)) a[j] = z;
      } else if (x <= a[y] + k - 1) {
        z = a[y];
        for (int(j) = y; (j) <= (x); ++(j)) a[j] = z;
      } else {
        z = y + 1;
        for (int(j) = y + 1; (j) <= (x); ++(j)) a[j] = z;
      }
      ret.push_back(z);
    }
  }
}
void print() {
  for (auto(x) : (ret)) printf("%d ", x);
  printf("\n");
}
int main() {
  parse();
  setup();
  solve();
  print();
}
