#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 1;
const int M = 1e9 + 7;
const double eps = 1e-6;
const double PI(acos(-1.0));
int n, k;
int a[N];
int c[300];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> k;
  memset(c, -1, sizeof c);
  for (int i = (1); i <= (n); i++) {
    cin >> a[i];
    if (c[a[i]] == -1) {
      int t = max(0, a[i] - k + 1);
      while (~c[t] && a[i] - c[t] >= k) t++;
      if (~c[t]) {
        for (int j = (t); j <= (a[i]); j++) c[j] = c[t];
      } else {
        for (int j = (t); j <= (a[i]); j++) c[j] = t;
      }
    }
    cout << c[a[i]] << " ";
  }
}
