#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <class T> ll size(const T &x) { return x.size(); }
#define rep(i,a,b) for(ll i = (a); i < (b); ++i)
#define iter(it,c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end();++it)
#define MOD 1000000007
#define pb push_back
#define fs first
#define sc second
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

const int INF = 2147493647;
const double pi = acos(-1);
const double EPS = 1e-9;

struct node {
	node* left = NULL;
	node* right = NULL;
	ll atl, atr, val;
	ll lazy = 0;
	ll mn,mx;
	node(node* l, node* r, int v, int al, int ar) {
		left = l; right = r; val = v;
		atl = al; atr = ar; mn = v; mx = v;
	}
	void lazyupdate(int l, int r, ll by) {
		if(lazy != 0) propagate();
		if(l > atr || r < atl) return;
		if(l <= atl && atr <= r) {
			val += (atr-atl+1)*by;
			mx += by; mn += by;
			if(left != NULL) {
				left->lazy += by;
				right->lazy += by;
			}
			return;
		}
		left->lazyupdate(l,r,by);
		right->lazyupdate(l,r,by);
		mn = min(left->mn, right->mn);
		mx = max(left->mx, right->mx);
		val = left->val+right->val;
	}
	ll lazyquery(int l, int r) {
		if(l > atr || r < atl) return 0;
		if(lazy != 0) propagate();
		if(l <= atl && atr <= r) return val;
		return left->lazyquery(l,r)+right->lazyquery(l,r);
	}
	int lazylowest(int l, int r) {
		if(l > atr || r < atl) return INF;
		if(lazy != 0) propagate();
		if(l <= atl && atr <= r) return mn;
		return min(left->lazylowest(l,r), right->lazylowest(l,r));
	}
	int lazyhighest(int l, int r) {
		if(l > atr || r < atl) return 0;
		if(lazy != 0) propagate();
		if(l <= atl && atr <= r) return mx;
		return max(left->lazyhighest(l,r), right->lazyhighest(l,r));
	}
	void propagate() {
		val += (atr-atl+1)*lazy;
		mn += lazy;
		mx += lazy;
		if(left != NULL) {
			right->lazy += lazy;
			left->lazy += lazy;
		}
		lazy = 0;
	}
};
node* build(int l, int r) {
	if(l > r) return NULL;
	if(l == r) return new node(NULL, NULL, 0, l, r);
	int m = (l+r)/2;
	node* left = build(l,m);
	node* right = build(m+1,r);
	node* cur = new node(left,right,0,l,r);
	return cur;
}


int main()
{
    ll n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    node* root = build(0,n);
    rep(i,0,n){
        if(s[i] == 'L') root->lazyupdate(i,i,1);
    }
    vii wrongs;
    rep(i,0,n-1){
        if(s[i] != s[i+1]) wrongs.pb(ii(i,i+1));
    }
    cout << n - 1 - max(0ll,((ll)(wrongs.size())-2*k)) << endl;
    //rep(i,0,wrongs.size()){
        //cout << wrongs[i].fs << ' ' << wrongs[i].sc << endl;
    //}
    /*ll cnt = 0;
    ll l = 0;
    ll r = (ll)(wrongs.size())-1;
    if(r == -1){
        cout << n-1 << endl;
        return 0;
    }
    while(cnt < k && l < r){
        ll f = wrongs[l].sc;
        ll s = wrongs[r].fs;
        root->lazyupdate(f,s,1);
        l++;
        r--;
        cnt++;
    }
    while(cnt < k && l < wrongs.size()){
        root->lazyupdate(0,wrongs[l].fs, 1);
        l++;
        cnt++;
        break;
    }

    vi A(n);
    rep(i,0,n){
        A[i] = (root->lazyquery(i,i)) % 2;
    }
    ll ans = 0;
    rep(i,0,n){
        if(A[i] == A[i+1]) ans++;
    }
    cout << ans << endl;*/
}


Measured memory_bytes: 18164