#include<bits/stdc++.h>
using namespace std;
#define fo(i, k, n) for (int i = k; i <= n; ++ i)
#define fod(i, k, n) for (int i = k; i >= n; -- i)
template <typename T, typename U>
static inline void maxx (T &x, U y) {
  if (x < y) {
    x = y;
  }
}
template <typename T, typename U>
static inline void minn (T &x, U y) {
  if (x > y) {
    x = y;
  }
}
template<typename T>
void read (T &x) {
  x = 0;
  T neg = 1;
  register T c = getchar ();
  if (c == '-') {
    neg = -1;
  }
  while (c < 48 || c > 57) {
    c = getchar ();
  }
  for (; c < 48 || c > 57; c = getchar ());
  for (; c <= 57 && c >= 48; c = getchar ()) {
    x = (x << 3) + (x << 1) + (c & 15);
  }
  x *= neg;
}
template<typename T>
void write (T x) {
  bool neg = 0;
  if (x < 0) {
    x *= -1;
    neg = 1;
  }
  char snum[65];
  int i = 0;
  do {
    snum[++ i] = x % 10 + '0';
    x /= 10;
  }
  while (x);
  //-- i;
  if (neg) {
    putchar ('-');
  }
  while (i > 0) {
    putchar (snum[i --]);
  }
}
///declare
typedef pair <int, int> ii;
bool cmp (ii a, ii b) {
  if (a.second - a.first == b.second - b.first) {
    return a.first < b.first;
  }
  else {
    return a.second - a.first > b.second - b.first;
  }
}
vector <ii> cc;
string s, tmp;
int res = 0, ans, n, k, l, r;
int main () {
  if (fopen ("test.inp", "r")) {
    freopen ("test.inp", "r", stdin);
  }
//  else {
//    freopen(".inp", "r", stdin);
//    freopen(".out", "w", stdout);
//  }

  read (n);
  read (k);
  cin >> s;
  s = '@' + s;
  s += '@';
  l = 1e9;
  r = 1e9;
  int tmpl, tmpr;
  tmpl = l;
  tmpr = r;
  fo (i, 1, n) {
    if (s[i] == 'R') {
      if (l == 1) {
        tmpl = l;
        tmpr = r;
      }
      if (l != 1e9 && l != 1) cc.push_back (ii (l, r));
      l = 1e9;
    }
    else {
      l = min (l, i);
      r = i;
    }
  }
  sort (cc.begin (), cc.end (), cmp);
  if (cc.size () < k && r != 1e9 && l != 1e9 && s[n] == 'L') cc.push_back (ii (l, r));
  if (cc.size () < k && tmpr != 1e9 && tmpl != 1e9 && s[1] == 'L') cc.push_back (ii (tmpl, tmpr));
  tmp = s;
  fo (j, 1, min (k, (int)cc.size ())) {
    fo (i, cc[j - 1].first, cc[j - 1].second) {
      tmp[i] = 'R';
    }
  }
  ans = 0;
  fo (i, 1, n) {
    if (tmp[i] == 'L' && tmp[i - 1] == 'L') {
      ++ ans;
    }
    else if (tmp[i] == 'R' && tmp[i + 1] == 'R') {
      ++ ans;
    }
  }
  res = max (res, ans);
  cc.clear ();
  l = -1e9;
  r = -1e9;
  tmpl = l;
  tmpr = r;
  fod (i, n, 1) {
    if (s[i] == 'L') {
      if (r == n) {
        tmpr = r;
        tmpl = l;
      }
      if (r != -1e9 && r != n) cc.push_back (ii (l, r));
      r = -1e9;
    }
    else {
      r = max (r, i);
      l = i;
    }
  }
  sort (cc.begin (), cc.end (), cmp);
  if (cc.size () < k && l != -1e9 && r != -1e9 && s[1] == 'R') cc.push_back (ii (l, r));
  if (cc.size () < k && tmpl != -1e9 && tmpr != -1e9 && s[n] == 'R') cc.push_back (ii (tmpl, tmpr));
  tmp = s;
  fo (j, 1, min (k, (int)cc.size ())) {//cerr << cc[j].first <<" " << cc[j].second << "\n";
    fo (i, cc[j - 1].first, cc[j - 1].second) {
      tmp[i] = 'L';
    }
  }
  ans = 0;
  fo (i, 1, n) {
    if (tmp[i] == 'L' && tmp[i - 1] == 'L') {
      ++ ans;
    }
    else if (tmp[i] == 'R' && tmp[i + 1] == 'R') {
      ++ ans;
    }
  }
  res = max (res, ans);
  write (res);
}


Measured memory_bytes: 1016