#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long INFl = 4223372036854775807ll;
const int inf = 1e9 + 7;
long long power(long long x, long long y, long long z) {
  long long t = 1;
  while (y > 0) {
    if (y % 2) {
      t = (t * x) % z;
    }
    x = (x * x) % z;
    y /= 2;
  }
  return t;
}
long long multipw(long long x, long long y, long long z) {
  long long sum = 0ll;
  while (y > 0) {
    if (y % 2) (sum += x) %= (long long)1e17;
    x = (x + x) % (long long)1e17;
    y /= 2;
  }
  return sum;
}
int movex[4] = {0, 1, -1, 0};
int movey[4] = {1, 0, 0, -1};
int movexx[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int moveyy[8] = {1, 1, 1, 0, -1, -1, -1, 0};
const int RIGHT = (1 << 20);
const int RR = 1e9;
const int SZ = 5e3 + 5;
const int _N = 5e5 + 10;
int n, k;
int a[_N];
int f[_N];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  memset(f, -1, sizeof(f));
  for (int i = 0; i < n; i++) {
    if (f[a[i]] != -1) {
      a[i] = f[a[i]];
      continue;
    }
    int left = a[i];
    int cnt = 0;
    while (left >= 0 && f[left] == -1 && cnt < k) {
      cnt++;
      left--;
    }
    left++;
    if (left != 0) {
      if (a[i] - k + 1 <= f[left - 1]) {
        left = f[left - 1];
      }
    }
    for (int j = left; j <= a[i]; j++) f[j] = left;
    a[i] = left;
  }
  for (int i = 0; i < n; i++) printf("%d ", a[i]);
  return 0;
}
