#include<cstdio>
#include<iostream>
using namespace std;
#define N 201000
int n,m,num,a[N],vis[N];
int ans=0x3f3f3f3f;
int main(){
freopen("sh.in","r",stdin);
scanf("%d%d",&n,&m);
int i,j=1;
for(i=1;i<=n;i++){
scanf("%d",&a[i]);
}
for(i=0;num<m&&i<=n;){
vis[a[++i]]++;
if(vis[a[i]]==1) num++;
}
if(i>n){
puts("NO");
return 0;
}
for(ans=i;i<=n;i++){
vis[a[i]]++;
if(vis[a[i]]==1) num++;
for(;(num>m)||(num==m&&vis[a[j]]>1);j++){
vis[a[j]]--;
if(vis[a[j]]==0) num--;
}
ans=min(ans,i-j+1);
}
printf("%d\n",ans);
return 0;
}