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

// DATA TYPES
typedef long long ll;
#define double long double
//

// CONTAINERS
#define vec vector
#define pb push_back
#define ALL(x) begin(x), end(x)
#define SZ(x) (int)x.size()
#define mp make_pair
#define ii pair<int, int>
#define F first
#define S second
template <typename T, typename U>
std::pair<T, U> operator+(const std::pair<T, U> &L, const std::pair<T,U> &R) {
  return {L.first + R.first, L.second + R.second};
}
//

// LOOP
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORE(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
//

// DEBUG
#define format(x) << #x << ": " << (x)
#define com << ", "
#define ndl << "\n"
#define debug1(x) cerr format(x) ndl;
#define debug2(x, y) cerr format(x) com format(y) ndl;
#define debug3(x, y, z) cerr format(x) com format(y) com format(z) ndl;
void debug_out() { cerr << "\n"; }
template <typename H, typename... T> 
void debug_out(H h, T... t) { cerr << " " << (h); debug_out(t...); }
#define DEBUG(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
// 

// Init variables here
const int N = 1e6 + 7;
int stNum[N];
int sz[N];
int leftmost[N];
int rightmost[N];

void make(int u) {
  stNum[u] = leftmost[u] = rightmost[u] = u, sz[u] = 1;
}

int find(int u) {
  if (stNum[u] != u) {
    stNum[u] = find(stNum[u]);
  }
  return stNum[u];
}

void merge(int u, int v) {
  int x = find(u), y = find(v);
  if (x != y) {
    if (sz[x] < sz[y]) {swap(x, y);} // size keeps the tree short
    stNum[y] = x;
    sz[x] += sz[y]; // add size of set y to set x
    leftmost[x] = min(leftmost[x], leftmost[y]);
    rightmost[x] = max(rightmost[x], rightmost[y]);
    // modification here

    // Sometimes the merge function is modified for solving a particular
    // problem. Example: https://codeforces.com/problemset/problem/722/C
    // In this problem, I know the weight of each node and when I merge two
    // sets, I need to find the total weight of the nodes in this set. So I
    // update the sum of the set inside this merge function:
    //sum[x] += sum[y]; sum[y] = sum[x];
  }
}

int n, k;
string s;
set<ii> st;
int newSz[N];

void f(int u) {
  int L = leftmost[u];
  int R = rightmost[u];
  int curSz = 0;
  if (L > 1) curSz++;
  if (R < n) curSz++;
  st.insert(mp(-curSz, u));
  newSz[u] = -curSz;
}

void before(int v, int &u) {
  st.erase(mp(newSz[v], v));
  merge(u, v);
  u = find(u);
}

void after(int v) {
  st.erase(mp(newSz[v], v));
  f(v);
}

void solve() {
  cin >> n >> k >> s;
  FORE(i, 1, n) make(i);
  FORE(i, 2, n) if (s[i - 2] == s[i - 1]) merge(i - 1, i);
  int u;
  FORE(i, 1, n) if ((u = find(i)) == i) f(u);
  int L, R;
  while (k and st.size() > 1) {
    k--;
    ii p = *st.begin(); st.erase(p);
    u = p.S;
    //debug3(u, leftmost[u], rightmost[u]);
    //debug1(p.F);
    if ((L = leftmost[u]) > 1) before(find(L - 1), u);
    if ((R = rightmost[u]) < n) before(find(R + 1), u);
    f(u);
    if ((L = leftmost[u]) > 1) after(find(L - 1));
    if ((R = rightmost[u]) < n) after(find(R + 1));
  }
  ll res = 0;
  for (ii p : st) res += (sz[p.S] - 1);
  cout << res << "\n";
  // read the question correctly (is y a vowel?)
  // look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie();
  //auto beginProgram = chrono::steady_clock::now();
  {
    solve();
  }
  //auto endProgram = chrono::steady_clock::now();

  return 0;
}




Measured memory_bytes: 17744