#include <bits/stdc++.h>
using namespace std;
int wa[100005];
int v[505];
int main() {
  int n, k, m, mm, flag = 0;
  int y, st, ss, d, c;
  cin >> n >> k;
  for (int i = 0; i < 256; i++) v[i] = -1;
  for (int i = 0; i < n; i++) {
    scanf("%d", &m);
    if (v[m] != -1) {
      cout << v[m] << ' ';
      continue;
    } else {
      y = m - 1;
      st = m;
      ss = m;
      d = m;
      c = k - 1;
      while (1) {
        if (y == -1) break;
        if (c == 0) break;
        if (v[y] != -1) {
          if (y - v[y] + 1 <= c) {
            ss = v[y];
            st = y + 1;
            break;
          } else
            break;
        }
        st = y;
        ss = y;
        c--;
        y--;
      }
      for (int j = st; j <= d; j++) v[j] = ss;
    }
    cout << v[m] << ' ';
  }
  cout << endl;
  return 0;
}
