#include <bits/stdc++.h>
using namespace std;
int val[1000], arr[100022], len[1000];
int main() {
  int n, m, i, j, k;
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; i++) scanf("%d", &arr[i]);
  memset(val, -1, sizeof(val));
  for (i = 0; i < n; i++) {
    int ele = arr[i];
    if (val[ele] != -1) continue;
    for (j = ele; j >= (ele - m + 1) && (val[j] == -1) && j >= 0; j--)
      ;
    if (j >= 0 && (val[j] != -1) && (len[j] + ele - j <= m)) {
      for (k = j + 1; k <= ele; k++) {
        val[k] = val[j];
        len[k] = len[j] + k - j;
      }
    } else {
      j++;
      for (k = j; k <= ele; k++) {
        val[k] = j;
        len[k] = k - j + 1;
      }
    }
  }
  for (i = 0; i < n; i++) printf("%d ", val[arr[i]]);
  return 0;
}
