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

const int MAXA = 1000000;

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

    int N, K;
    cin >> N >> K;

    vector<int> a(N);
    vector<int> freq(MAXA + 1);

    for (int &x : a) {
        cin >> x;
        freq[x]++;
    }

    vector<bool> important(MAXA + 1, false);

    int found = 0;

    for (int x = 1; x <= MAXA && found < K; x++) {
        if (freq[x] > 0) {
            important[x] = true;
            found++;
        }
    }

    int leftmost = N;
    int rightmost = -1;

    for (int i = 0; i < N; i++) {
        if (important[a[i]]) {
            leftmost = min(leftmost, i);
            rightmost = max(rightmost, i);
        }
    }

    long long ans =
        1LL * (leftmost + 1) * (N - rightmost);

    cout << ans << '\n';
}
