#include <bits/stdc++.h>
int n, m, c[256];
int main() {
  int a, j;
  scanf("%d%d", &n, &m);
  memset(c, -1, sizeof(c));
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a);
    if (~c[a])
      printf("%d ", c[a]);
    else {
      j = a;
      while (j && !~c[j - 1] && j > a - m + 1) --j;
      if (j && ~c[j - 1] && a - c[j - 1] < m)
        c[j] = c[j - 1];
      else
        c[j] = j;
      for (int k = j + 1; k <= a; ++k) c[k] = c[j];
      printf("%d ", c[j]);
    }
  }
  return 0;
}
