#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#ifdef LOCAL
#define debug(...) \
  std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}
using namespace std;
using int64 = long long;

template <class _Tp>
class FenwickTree {
 public:
  FenwickTree(const std::vector<_Tp>& data) : n_(data.size() + 1), data_(data) {
    initialize();
  }

  void add(int pos, _Tp value) {
    ++pos;
    while (pos < n_) {
      node_[pos] += value;
      pos += pos & -pos;
    }
  }

  // return sum of [0, i]
  _Tp get(int pos) {
    ++pos;
    _Tp sum = 0;
    while (pos > 0) {
      sum += node_[pos];
      pos -= pos & -pos;
    }
    return sum;
  }

  // return sum of [l, rihgt]
  _Tp get(int l, int r) { return get(r) - get(l - 1); }

  // return the first k where sum of [0, k] >= value
  // use only when all element in data >= 0
  int lower_bound(_Tp value) {
    if (value <= 0) return 0;
    int pos = 0;
    int k = 1;
    while (k < n_ - 1) k <<= 1;
    while (k > 0) {
      if (pos + k <= n_ - 1 && node_[pos + k] < value) {
        value -= node_[pos + k];
        pos += k;
      }
      k >>= 1;
    }
    return pos;
  }

  // for range add query
  class RAQ {
   public:
    RAQ(const std::vector<_Tp>& data)
        : n_(data.size()),
          ft1_(FenwickTree<_Tp>(data)),
          ft2_(FenwickTree<_Tp>(data)) {}

    // add value range [l, r)
    void add(int l, int r, _Tp value) {
      add(ft1_, l, r, value);
      add(ft2_, l, r, -value * static_cast<_Tp>(l - 1));
      add(ft2_, r, n_, value * static_cast<_Tp>(r - l));
    }

    // get sum of [0, i]
    _Tp get(int pos) {
      return ft1_.get(pos) * static_cast<_Tp>(pos) + ft2_.get(pos);
    }

    // get sum of [l, r]
    _Tp get(int l, int r) { return get(r) - get(l - 1); }

   private:
    int n_;
    FenwickTree<_Tp> ft1_;
    FenwickTree<_Tp> ft2_;
    void add(FenwickTree<_Tp>& ft, int l, int r, _Tp value) {
      ft.add(l, value);
      ft.add(r, -value);
    }
  };

 private:
  int n_;
  std::vector<_Tp> data_;
  std::vector<_Tp> node_;
  void initialize() {
    node_.assign(n_ + 1, 0);
    for (int i = 0; i < n_ - 1; ++i) add(i, data_[i]);
  }
};

int main() {
  int N, K;
  cin >> N >> K;
  string s;
  cin >> s;
  vector<pair<int, int>> l;
  vector<pair<int, int>> r;
  vector<int> l_renzoku, r_renzoku;
  int r_begin, l_begin;
  if (s[0] == 'R') {
    r_begin = 0;
    l_begin = -1;
    l.push_back(make_pair(0, 0));
  } else {
    r_begin = -1;
    l_begin = 0;
    r.push_back(make_pair(0, 0));
  }
  for (int i = 1; i < N; i++) {
    if (s[i - 1] == 'L' && s[i] == 'R') {
      r_begin = i;
      l.push_back(make_pair(l_begin, i - 1));
      l_renzoku.push_back(i - l_begin - 1);
      r_renzoku.push_back(0);
      l_begin = -1;
    } else if (s[i - 1] == 'R' && s[i] == 'L') {
      l_begin = i;
      r.push_back(make_pair(r_begin, i - 1));
      r_renzoku.push_back(i - r_begin - 1);
      l_renzoku.push_back(0);
      r_begin = -1;
    } else {
      r_renzoku.push_back(0);
      l_renzoku.push_back(0);
    }
  }
  if (l_begin != -1) {
    l.push_back(make_pair(l_begin, N - 1));
    r.push_back(make_pair(N - 1, N - 1));
    l_renzoku.push_back(N - 1 - l_begin);
    r_renzoku.push_back(0);
  } else {
    r.push_back(make_pair(r_begin, N - 1));
    l.push_back(make_pair(N - 1, N - 1));
    r_renzoku.push_back(N - 1 - r_begin);
    l_renzoku.push_back(0);
  }
  if (l.size() == 1 || l.size() == 0 || r.size() == 1 || r.size() == 0) {
    cout << N - 1 << endl;
    return 0;
  }
  debug(l, r);
  debug(l_renzoku, r_renzoku);
  FenwickTree<int> ft_l(l_renzoku);
  FenwickTree<int> ft_r(r_renzoku);
  int K_ = K;
  K = min(K, (int)l.size() - 1);
  int l_max = 0;
  for (int i = 0; i < (int)l.size() - K; i++) {
    int tmp = l[i + K].second - l[i].first;
    int l_happy =
        ft_l.get(0, l[i].first - 1) + ft_l.get(l[i + K].second + 1, N - 1);
    int r_happy =
        ft_r.get(0, l[i].first - 1) + ft_r.get(l[i + K].second + 1, N - 1);
    debug(tmp, l_happy, r_happy);
    l_max = max(l_max, tmp + l_happy + r_happy);
  }
  K = min(K_, (int)r.size() - 1);
  int r_max = 0;
  for (int i = 0; i < (int)r.size() - K; i++) {
    int tmp = r[i + K].second - r[i].first;
    int r_happy =
        ft_r.get(0, r[i].first - 1) + ft_r.get(r[i + K].second + 1, N - 1);
    int l_happy =
        ft_l.get(0, r[i].first - 1) + ft_l.get(r[i + K].second + 1, N - 1);
    r_max = max(r_max, tmp + r_happy + l_happy);
  }
  debug(l_max, r_max);
  cout << max(l_max, r_max) << endl;
  return 0;
}

Measured memory_bytes: 6624