#include <bits/stdc++.h>
using namespace std;
using namespace std;
long long arr[200005];
long long col[256];
deque<long long> q;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long T, N, i, j, k, L, l, m, n;
  long long K;
  cin >> N >> K;
  memset(col, -1, sizeof(col));
  for (i = 0; i < N; i++) {
    cin >> arr[i];
    q.push_back(arr[i]);
  }
  while (!q.empty()) {
    long long t = q.front();
    if (col[t] != -1) {
      q.pop_front();
      continue;
    }
    vector<long long> temp;
    temp.push_back(t);
    q.pop_front();
    sort(temp.begin(), temp.end());
    long long start = temp[temp.size() - 1];
    long long _end =
        ((((long long)0) > (start - K + 1)) ? ((long long)0) : (start - K + 1));
    if (start < K) {
      for (i = 0; i <= start; i++) col[i] = 0;
      continue;
    }
    long long color = -1;
    for (i = _end; i <= start; i++) {
      if (col[i] == -1 and color == -1) color = i;
      if (col[i] == i) color = i;
      if (col[i] == -1) col[i] = color;
    }
  }
  for (i = 0; i < N; i++) {
    cout << col[arr[i]] << " ";
  }
  cout << endl;
}
