#include <iostream>

using namespace std;

int main()
{
    int N,K;
    cin >> N >> K;

    char tep,last='P'; int count=0;
    while(cin >> tep)
    {
        if(tep!=last) count++;
        last = tep;
    }

    int i;
    for(i=0;i<K;i++)
    {
        if(count > 2) count = count -2;
        else count--;
        if(count == 1) break;     
    }

    cout << N-count;
}