#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int i;
  int a[n], b[256] = {0};
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  int c[256] = {0};
  for (i = 0; i < 256; i++) {
    b[i] = i;
  }
  for (i = 0; i < n; i++) {
    int q = a[i];
    if (b[q] != q or c[q] != 0) {
      cout << b[q] << " ";
    } else {
      int k1 = k;
      while (b[q - k1 + 1] != q - k1 + 1) {
        k1--;
      }
      for (int j = 0; j < k1; j++) {
        b[q - k1 + 1 + j] = q - k1 + 1;
        c[q - k1 + 1 + j] = 1;
      }
      cout << b[q] << " ";
    }
  }
  return 0;
}
