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

int main() {
  int n, k, i, ans = 0;
  char s[2];
  cin >> n >> k >> s[0];
  for (i = 1; i < n; i++) {
    cin >> s[i%2];
    if (s[i%2] == s[(i-1)%2]) ans++;
  }
  cout << min(n-1, ans+2*k) << endl;
}