#include <bits/stdc++.h>
using namespace std;
const long long int N = 256, mod = 1e9 + 7, bit = 31;
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long int pro = 1, temp, t, n, m, k, i, j, l, r, mid, x, y, z, rem,
                carry = 0, ind, ans = 0, mx = -LONG_LONG_MAX,
                mn = LONG_LONG_MAX, cnt = 0, curr = 0, prev, nxt, sum = 0,
                flag = 1, i1 = -1, i2 = -1;
  cin >> n >> k;
  long long int key[300];
  for (i = 0; i <= 299; i++) {
    key[i] = -1;
  }
  long long int a[n + 1];
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (i = 1; i <= n; i++) {
    x = a[i];
    if (key[x] == -1) {
      for (j = max(0ll, x - k + 1); j <= x; j++) {
        if (key[j] == -1) {
          temp = j;
          break;
        } else if (x <= key[j] + k - 1) {
          temp = key[j];
          break;
        }
      }
      for (j = temp; j <= x; j++) {
        key[j] = temp;
      }
    }
    a[i] = key[a[i]];
  }
  for (i = 1; i <= n; i++) {
    cout << a[i] << ' ';
  }
  cout << '\n';
  return 0;
}
