#include <bits/stdc++.h>
using namespace std;
const int maxn = 123456;
char ch[maxn];
int ai[maxn];
int fa[300];
int n, m;
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    for (int i = 0; i < 300; i++) fa[i] = -1;
    fa[0] = 0;
    for (int i = 1; i <= n; i++) scanf("%d", &ai[i]);
    for (int i = 1; i <= n; i++) {
      if (fa[ai[i]] != -1) {
        printf("%d ", fa[ai[i]]);
      } else {
        int e = -1;
        int end = -1;
        for (int j = ai[i]; j > ai[i] - m; j--) {
          if (fa[j] == -1) {
            end = j;
            continue;
          }
          if (fa[j] == j) {
            e = j;
          }
        }
        if (e == -1) {
          for (int j = ai[i]; j >= end; j--) {
            fa[j] = end;
          }
        } else {
          for (int j = e; j <= ai[i]; j++) fa[j] = e;
        }
        printf("%d ", fa[ai[i]]);
      }
    }
    printf("\n");
  }
  return 0;
}
