#include <cstdio>
using namespace std;

int A[100010], cnt[100010];
int main() {
    int N, K; scanf("%d%d", &N, &K);
    for(int i=0; i<N; i++) {
        scanf("%d", &A[i]);
    }

    int r = 0, sum = 0, ans = N+1;
    for(int l=0; l<N; l++) {
        while(sum < K && r < N) {
            if(!cnt[ A[r] ] && A[r] <= K) sum++;
            cnt[ A[r++] ]++;
        }
        
        while(l < r) {
            if(--cnt[ A[l] ] == 0 && A[l] <= K) break;
            l++;
        }
        if(sum == K && ans > r - l) ans = r - l;
        if(A[l] <= K) sum--;
    }
    printf("%d\n", (ans == N+1 ? 0 : ans));
    return 0;
}
