#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define rrepSE(i,s,e) for (int i = (s); i > (e); i--)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
#define DEBUG_PRINT(var) std::cout << #var << " = " << var << "\n";

vector<pint> reArrange(vector<pint> res) {
    vector<pint> res2(1, res[0]);
    repSE (i,1,res.size()) {
        if (res2.back().first == res[i].first) {
            res2.back().second += res[i].second;
        }
        else {
            res2.push_back(res[i]);
        }
    }
    return res2;
}

int main()
{
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<int> si(n);
    rep(i,n) {si[i] = (s[i] == 'L') ? 0 : 1;}
    vector<pint> res(1, pint(si[0], 0));
    for (int p : si) {
        if (res.back().first == p) {
            res.back().second ++;
        }
        else {
            res.emplace_back(p, 1);
        }
    }
    // vector<pint> s0, s1;
    // rep (i, res.size()) {
    //     auto ele = res[i];
    //     if (ele.first == 0) s0.emplace_back(ele.second, i);
    //     else s1.emplace_back(ele.second, i);
    // }
    // cout << "CP1: " << res << endl;
    int rm = k;
    // rep (i, res.size()) {
    //     if (rm == 0) break;
    //     if (i > 0 && res[i].second > 1) {
    //         res[i].first = 1 - res[i].first;
    //         rm --;
    //         i++;
    //     }
    // }
    // cout << "CP2: " << res << endl;
    // res = reArrange(res);
    // cout << "CP3: " << res << endl;
    repSE (i, 1, res.size() - 1) {
        if (rm == 0) break;
        res[i].first = 1 - res[i].first;
        rm --;
        i++;
    }
    // cout << "CP4: " << res << endl;
    res = reArrange(res);
    // cout << "CP5: " << res << endl;

    if (rm > 0 && res.size() > 1) {
        res[0].first = 1 - res[0].first;
        res = reArrange(res);
        rm--;
    }
    // cout << "CP6: " << res << endl;
    if (rm > 0 && res.size() > 1) {
        res.back().first = 1 - res.back().first;
        res = reArrange(res);
        rm --;
    }
    // cout << "CP7: " << res << endl;

    int ans = 0;
    for(auto ele : res) {
        ans += max(ele.second - 1, 0);
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 6784