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

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

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

    vector<int> a(N);

    int mn = INT_MAX;

    for (int &x : a) {
        cin >> x;
        mn = min(mn, x);
    }

    long long total = 1LL * N * (N + 1) / 2;
    long long bad = 0;

    long long len = 0;

    for (int x : a) {
        if (x == mn) {
            bad += len * (len + 1) / 2;
            len = 0;
        } else {
            len++;
        }
    }

    bad += len * (len + 1) / 2;

    cout << total - bad << '\n';
}
