#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read(){
int x = 0,f = 1;
char ch = getchar();
while(ch < '0' || ch > '9'){
if(ch == '-')
f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9'){
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
inline void write(int x)
{
char F[200];
int tmp = x > 0 ? x : -x;
if(x<0) putchar('-');
int cnt = 0;
while(tmp > 0){
F[cnt++] = tmp%10+'0';
tmp /= 10;
}
while(cnt > 0) putchar(F[--cnt]);
putchar('\n');
}
int n, k, a[200005], cnt, out[200005], am[200005];
vector<int> d[200005];
set<int> s;
int main(){
n = read(), k = read();
if(k == 1){
for(int i = 1; i <= n; ++i) printf("%d\n", i);
return 0;
}
for(int i = 1; i <= n; ++i){
a[i] = read();
set<int>::iterator it = lower_bound(s.begin(), s.end(), a[i]);
if(it == s.end()){
d[++cnt].push_back(a[i]);
am[a[i]] = cnt;
s.insert(a[i]);
}
else{
int x = *it;
d[am[x]].push_back(a[i]);
am[a[i]] = am[x];
s.erase(x);
if(d[am[x]].size() == k){
for(int j = 0; j < d[am[x]].size(); ++j){
out[d[am[x]][j]] = i;
}
continue;
}
s.insert(a[i]);
}
}
for(int i = 1; i <= n; ++i){
if(!out[i]) puts("-1");
else printf("%d\n", out[i]);
}
return 0;
}
38AC 4WA 1TLE 求调