#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k;
  cin >> n >> k;
  long long int a[n + 1];
  for (long long int i = (long long int)1; i <= (long long int)n; i++)
    cin >> a[i];
  long long int present[257];
  long long int val[257];
  memset(present, -1, sizeof(present));
  memset(val, -1, sizeof(val));
  val[0] = 0;
  bool small = false;
  long long int ptr = -1;
  for (long long int i = (long long int)1; i <= (long long int)n; i++) {
    small = false;
    if (present[a[i]] == -1 && val[a[i]] == -1) {
      ptr = max(0LL, a[i] - k + 1);
      for (long long int j = (long long int)a[i] - 1;
           j >= (long long int)max(0LL, a[i] - k + 1); j--) {
        if (present[j] != -1) {
          ptr = j;
          if (val[j] >= a[i] - k + 1) {
            small = true;
          }
          break;
        }
      }
      if (small) {
        for (long long int j = (long long int)ptr + 1; j <= (long long int)a[i];
             j++)
          val[j] = val[ptr];
      } else {
        if (present[ptr] != -1) ptr++;
        for (long long int j = (long long int)ptr; j <= (long long int)a[i];
             j++)
          val[j] = ptr;
      }
      present[a[i]] = 1;
    }
  }
  for (long long int i = (long long int)1; i <= (long long int)n; i++)
    cout << val[a[i]] << " ";
}
