#include <bits/stdc++.h>
using ll = long long;
using namespace std;

const int inf = 1e9;
const ll linf = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, k; cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i], a[i]--;
    
    int res = inf;
    int l = 0, r = 0, s = 0;
    vector<int> count(k, 0);
    for (; l < n; l++) {
        while (r < n && s < k) {
            if (a[r] < k && ++count[a[r]] == 1) s++;
            r++;
        }
        if (s < k) break;
        res = min(res, r - l);
        if (a[l] < k && --count[a[l]] == 0) s--;
    }
    cout << (res <= n ? res : 0) << endl;
    return 0;
}
