#include <bits/stdc++.h>
using namespace std;
int X[280];
bool vis[280];
int main() {
  int n, k;
  cin >> n >> k;
  int temp;
  memset(X, -1, sizeof(X));
  for (int i = 0; i < n; i++) {
    cin >> temp;
    if (X[temp] == -1) {
      int a = temp;
      while (vis[a - 1] == false && a >= temp - k + 2 && a >= 1) a--;
      X[a] = a;
      for (int i = a + 1; i < a + k && X[i] != i; i++) {
        X[i] = a;
      }
    }
    vis[temp] = true;
    cout << X[temp] << ' ';
  }
}
