#include <bits/stdc++.h>
using namespace std;
constexpr long long R = 2e5 + 69, INF = 2e9 + 6969;
int n, t[R], k, rep[256];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < (1 << 8); ++i) rep[i] = -1;
  for (int i = 0; i < n; ++i) scanf("%d", &t[i]);
  for (int i = 0; i < n; ++i) {
    if (rep[t[i]] != -1) continue;
    int y = t[i], x = t[i];
    while (y >= 0 && rep[y] == -1 && x - y + 1 <= k) --y;
    if (y >= 0) {
      int col = 0;
      if (rep[y] + k - 1 >= x) {
        col = rep[y];
      } else {
        col = max(y + 1, x - k + 1);
      }
      for (int j = col; j <= t[i]; ++j) rep[j] = col;
    } else {
      int col = max(0, x - k + 1);
      for (int j = col; j <= t[i]; ++j) rep[j] = col;
    }
  }
  for (int i = 0; i < n; ++i) printf("%d ", rep[t[i]]);
  puts("");
  return 0;
}
