#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
using namespace std;
const int MOD = 1000000007;
const int N = 200005;
const int M = 305;
int n, k, maxn = -1, a[N], vis[M];
signed main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  memset(vis, -1, sizeof vis);
  for (int i = 1; i <= n; i++) {
    if (vis[a[i]] != -1) continue;
    int now = 0, marn = 0;
    for (int j = a[i]; j >= max(a[i] - k + 1, 0); j--) {
      if (vis[j] != -1) {
        marn = j;
        break;
      }
      now = j;
    }
    if (vis[marn] != -1 && a[i] - vis[marn] + 1 <= k) now = vis[marn];
    for (int j = now; j <= a[i]; j++) vis[j] = now;
  }
  int siz = 0;
  for (int i = 0; i <= 255; i++) {
    if (vis[i] != -1) {
      siz = 0;
      continue;
    }
    if (!i)
      vis[i] = 0;
    else
      vis[i] = vis[i - 1];
    if (!siz) vis[i] = i;
    siz++;
    siz %= k;
  }
  for (int i = 1; i <= n; i++) printf("%d ", vis[a[i]]);
  return 0;
}
