#include <bits/stdc++.h>
using namespace std;
int p[100024];
int vis[333];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &p[i]);
  memset(vis, -1, sizeof(vis));
  for (int i = 1; i <= n; i++) {
    int l = max(p[i] - k + 1, 0);
    bool ha = 0;
    for (int j = p[i]; j >= l; j--) {
      if (vis[j] != -1 && vis[j] + k - 1 >= p[i]) {
        vis[p[i]] = vis[j];
        ha = 1;
        break;
      }
    }
    if (ha) continue;
    int mmin = 333;
    for (int j = p[i]; j >= l; j--) {
      if (vis[j] != -1) {
        break;
      }
      mmin = min(j, mmin);
    }
    for (int j = mmin; j <= p[i]; j++) {
      vis[j] = mmin;
    }
  }
  for (int i = 1; i <= n; i++) printf("%d%c", vis[p[i]], " \n"[i == n]);
  return 0;
}
