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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main()
{
		int N, K;
	cin >> N >> K;
	string S;
	cin >> S;
	string T = S,U=S,V=S;
	int x = 0;
	fw(K) {
		if (x >= N) { break; }
		if (S.at(x)=='R') {
			w--;
			x++;
			continue;
		}
		int y = x;
		while (y+1<N&&S.at(y)==S.at(y+1)) {
			y++;
		}

		fzg(y+1,x) {
			if (S.at(z)=='R') {
				S.at(z) = 'L';
			}
			else {
				S.at(z) = 'R';
			}
		}
		x = y + 1;
	}
	x = N-1;
	fw(K) {
		if (x <0) { break; }
		if (T.at(x) == 'R') {
			w--;
			x--;
			continue;
		}
		int y = x;
		while (y - 1>=0&&T.at(y) == T.at(y - 1)) {
			y--;
		}

		fzg(x +1, y) {
			if (T.at(z) == 'R') {
				T.at(z) = 'L';
			}
			else {
				T.at(z) = 'R';
			}
		}
		x = y - 1;
	}
	x = 0;
	fw(K) {
		if (x >= N) { break; }
		if (U.at(x) == 'L') {
			w--;
			x++;
			continue;
		}
		int y = x;
		while (y + 1<N&&U.at(y) == U.at(y + 1)) {
			y++;
		}

		fzg(y + 1, x) {
			if (U.at(z) == 'R') {
				U.at(z) = 'L';
			}
			else {
				U.at(z) = 'R';
			}
		}
		x = y + 1;
	}
	x = N - 1;
	fw(K) {
		if (x <0) { break; }
		if (V.at(x) == 'L') {
			w--;
			x--;
			continue;
		}
		int y = x;
		while (y - 1 >= 0 && V.at(y) == V.at(y - 1)) {
			y--;
		}

		fzg(x + 1, y) {
			if (V.at(z) == 'R') {
				V.at(z) = 'L';
			}
			else {
				V.at(z) = 'R';
			}
		}
		x = y - 1;
	}
	int ans = 0,sum=0,ans1=0,sum2=0;
	fx(S.size()-1) {
		if (S.at(x)==S.at(x+1)) {
			ans++;
		}
	}
	fx(T.size() - 1) {
		if (T.at(x) == T.at(x + 1)) {
			sum++;
		}
	}
	fx(U.size() - 1) {
		if (U.at(x) == U.at(x + 1)) {
			ans1++;
		}
	}
	fx(V.size() - 1) {
		if (V.at(x) == V.at(x + 1)) {
			sum2++;
		}
	}
//	ce(S)
	//	ce(T)
		ce(max({ ans,sum ,ans1,sum2}))
    return 0;
}



Measured memory_bytes: 640