#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n), g(256, -1);
  for (int &e : a) cin >> e;
  for (int i = 0; i < n; i++) {
    if (g[a[i]] != -1)
      a[i] = g[a[i]];
    else {
      int temp = max(0, a[i] - k + 1);
      for (int j = a[i] - 1; j >= temp; j--)
        if (g[j] != -1) {
          if (g[j] >= temp) {
            for (int k = g[j]; k <= a[i]; k++) g[k] = g[j];
            a[i] = g[j];
            break;
          }
          for (int k = j + 1; k <= a[i]; k++) g[k] = j + 1;
          a[i] = j + 1;
          break;
        } else if (j == temp) {
          for (int k = temp; k <= a[i]; k++) g[k] = temp;
          a[i] = temp;
        }
    }
  }
  for (int &e : a) cout << e << " ";
  cin >> n;
}
