#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
int a[N];
int vis[300];
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  memset(vis, 0, sizeof(vis));
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  int top = 1;
  for (int i = 0; i < n; i++) {
    if (i) printf(" ");
    if (vis[a[i]] || vis[a[i] + 1]) {
      for (int j = a[i]; j >= 0; j--) {
        if (!vis[j]) {
          printf("%d", j);
          break;
        }
      }
    } else {
      int t = a[i] - k + 1;
      int t1;
      if (t <= 0)
        t1 = 0;
      else {
        if (vis[t]) {
          for (int j = t; j <= a[i]; j++) {
            if (!vis[j]) {
              t1 = j;
              break;
            }
          }
        } else {
          t1 = t;
        }
      }
      printf("%d", t1);
      for (int j = t1 + 1; j <= a[i]; j++) {
        vis[j] = top;
      }
      top++;
    }
  }
  printf("\n");
  return 0;
}
