#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, i, j, ans[100005];
  while (cin >> n >> k) {
    for (i = 0; i < 256; i++) ans[i] = -1;
    for (i = 0; i < n; i++) {
      int x;
      cin >> x;
      if (ans[x] == -1)
        for (j = x - k + 1 > 0 ? x - k + 1 : 0; j <= x; j++) {
          if (ans[j] == -1 || ans[j] == j) {
            for (int t = j; t <= x; t++) {
              ans[t] = j;
            }
          }
        }
      cout << ans[x] << ' ';
    }
    cout << endl;
  }
}
