#include <bits/stdc++.h>
using namespace std;
int n, m, v[260];
int main() {
  cin >> n >> m;
  memset(v, -1, sizeof(v));
  v[0] = 0;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    if (v[x] == -1) {
      for (int i = x - m + 1; i <= x; i++) {
        if (v[i] == -1 || v[i] == i) {
          for (int j = i; j <= x; j++) v[j] = i;
          break;
        }
      }
    }
    cout << v[x] << " ";
  }
  return 0;
}
