#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int a[N];
int pre[256];
int cnt[256], nxt[256];
int main() {
  memset(pre, -1, sizeof(pre));
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), cnt[a[i]]++;
  int pos = -1;
  for (int i = 0; i < 256; i++) {
    nxt[i] = pos;
    if (cnt[i]) pos = i;
  }
  for (int i = 1; i <= n; i++) {
    if (pre[a[i]] == -1) {
      int pos = -1;
      for (int j = a[i] - 1; j > max(a[i] - k, -1); j--)
        if (pre[j] != -1) {
          pos = j;
          break;
        }
      if (pos == -1)
        for (int j = max(a[i] - k + 1, 0); j <= a[i]; j++)
          pre[j] = max(a[i] - k + 1, 0);
      else {
        int ans;
        if (a[i] - pre[pos] + 1 <= k)
          ans = pre[pos];
        else
          ans = pos + 1;
        for (int j = pos + 1; j <= a[i]; j++) pre[j] = ans;
      }
    }
    printf("%d ", pre[a[i]]);
  }
}
