#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N,K;
    cin >> N >> K;
    vector<int> a(N);
    for (int i = 0; i < N; i++){
        cin >> a.at(i);
    }

    vector<int> hindo(N);
    for (int i = 0; i < N; i++){
        hindo.at(a.at(i))++;
    }
    vector<vector<int>>hako(K,vector<int>(0));
    int MAX = 0;
    for (int i = 0; i < K; i++){
        for (int j = 0; j < N; j++){
            if (hindo.at(j) > 0){
                hako.at(i).push_back(j);
                hindo.at(j)--;
            }else{
                break;
            }
        }
        MAX += hako.at(i).size();
    }
    cout << MAX << endl;
}
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI 3.14159265359
#define rep(i, n) for (int i = 0; i < (n); i++)
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

int main() {
    int n;
    ll ans = 0;
    string s;
    cin >> n >> s;
    vector<vector<int>> count(n + 1, vector<int>(4, 0));
    string ch = "ATCG";
    for (int i = 0; i < n; i++) {
        if (i != 0) {
            for (int j = 0; j < 4; j++) count[i + 1][j] += count[i][j];
        }
        for (int j = 0; j < 4; j++)
            if (s[i] == ch[j]) count[i + 1][j]++;
    }

    for (int st = 0; st < n; st++) {
        for (int le = 2; st + le < n + 1; le++) {
            int num[4] = {0};
            for (int i = 0; i < 4; i++)
                num[i] = count[st + le][i] - count[st][i];
            if (num[0] == num[1] && num[2] == num[3]) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}