#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define inf 1000000000000000001
#define mod 1000000007
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL);
#define precise fixed(cout);cout<<setprecision(16);
#define Set(N,p) N=((N)|((1LL)<<(p)))
#define Reset(N,p) N=((N)&(~((1LL)<<(p))))
#define Check(N,p) (!(((N)&((1LL)<<(p)))==(0)))
#define POPCOUNT __builtin_popcountll
#define RIGHTMOST __builtin_ctzll
#define LEFTMOST(x) (63-__builtin_clzll((x)))
#define NUMDIGIT(x,y) (((vlong)(log10((x))/log10((y))))+1)
#define OUT(x) for(auto a:x) cout << a << " "; cout << endl;
#define OK cout << "@===================ok===================@" <<endl;
#define WTF cout <<"< "<<lo<<" | "<< hi <<" >" << endl;

using namespace std;

int main()
{
    ll n,x;
    cin >> n >> x;
    string s;
    cin >> s;
    ll res=x;
    for(auto a:s){
        if(a=='x') res--;
        else res++;
        if(res<0) res=0;
    }
    cout << res <<"\n";
}

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

#define all(x) (xi).begin(), (x).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define un_map unordered_map
#define rep(i,a,n) for (int i = a; i < n; ++i) 
#define rrep(i,a,n) for (int i = a; i >= n; --i) 
#define irep(i,a,n,inc) for (int i = a; i < n; i += inc) 
#define endl "\n"

typedef long long ll;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
 
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define int long long


int power_mod(int a, int b, int mo) {
	int ans = 1;
	while (b) {
		if(b & 1) {
			ans = (ans % mo * a % mo) % mo;
		}
		a = (a % mo * a % mo) % mo;
		b /= 2;
	  }
	return ans;
}


void print(vector<vector<int>> &v) {
  for (int i = 0; i < (int)v.size(); ++i) {
    cout << i << " : ";
    for (int j = 0; j < (int)v[i].size(); ++j) {
      cout << v[i][j] << " ";
    } 
    cout << endl;
  }
  cout << endl;
}


int32_t main() {
   int n, k;
  cin >> n >> k;
  vector<int> v(n);
  for (int i = 0; i < n; ++i) cin >> v[i];
  vector<int> m(4e5);
  vector<vector<int>> ans(4e5);
  for (int i = 0; i < n; ++i) {
    ans[m[v[i]]].push_back(v[i]);
    m[v[i]]++;
  }
  for (int i = 0; i < 4e5; ++i) {
    sort(ans[i].begin(), ans[i].end());
  }
  //int maxm = *max_element(all(v));
  int sum = 0;
  vector<int> res;
  for (int i = 0; i < 4e5; ++i) {
    int size = (int)ans[i].size();
    //if (size) {
      //debug(i, ans[i]);
      int p = -1;
      //int val = ans[i][size - 1];
      for (int j = 0; j < size; ++j) {
        if (ans[i][j] == p + 1) p++;
        else break; 
      }
      //debug(p, val);
      //if (p == val + 1) {
        res.push_back(p + 1);
     // }
   // }
  }
  sort(res.rbegin(), res.rend());
  for (int i = 0; i < k; ++i) {
    sum += res[i];
  }
  cout << sum;
}

