#include <bits/stdc++.h>
using namespace std;
int gcd(int x, int y) {
  if (y == 0) {
    return x;
  }
  return gcd(y, x % y);
}
long long int lgcd(long long int x, long long int y) {
  if (y == 0) {
    return x;
  }
  return lgcd(y, x % y);
}
long long int pow(long long int a, long long int b,
                  long long int m = 1000000007) {
  long long int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = (res * a) % m;
    }
    a = (a * a) % m;
    b >>= 1;
  }
  return res;
}
int a[100010];
int ans[260];
int b[100010];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, k, i, j, l;
  cin >> n >> k;
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < 256; i++) ans[i] = -1;
  ans[0] = 0;
  for (i = 0; i < n; i++) {
    if (ans[a[i]] != -1) {
      b[i] = ans[a[i]];
    } else {
      j = a[i] - 1;
      while (ans[j] == -1 && j >= a[i] - k + 1) {
        j--;
      }
      if (ans[j] != -1 && ans[j] + k - 1 >= a[i]) {
        b[i] = ans[j];
        for (l = j + 1; l <= a[i]; l++) {
          ans[l] = ans[j];
        }
      } else {
        b[i] = j + 1;
        for (l = j + 1; l <= a[i]; l++) ans[l] = j + 1;
      }
    }
    cout << b[i] << " ";
  }
  return 0;
}
