#include <iostream>

using namespace std;

int n, k;
int main()
{
    cin >> n >> k;
    char c, cc;
    int kk = 0;
    cin >> c;
    for (int i = 0; i != n - 1; ++i)
    {
        cin >> cc;
        if (cc != c) ++kk;
        c = cc; 
    }
    if (kk < 2 * k) kk = 0;
    else kk -= 2 * k;
    cout << n - 1 - kk << endl;
    return 0;
}