#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void smn(T &a, const T &b) {
  if (b < a) a = b;
}
template <class T>
inline void smx(T &a, const T &b) {
  if (b > a) a = b;
}
template <class T>
inline T rev(const T &a) {
  T _ = a;
  reverse(_.begin(), _.end());
  return _;
}
const double eps = 1e-9;
const long double leps = 1e-14;
class node {
 public:
  int c[2];
  int sb[2];
  bool rev;
};
string inp;
int n, m;
node seg[(1 << 21) + 10];
void fix(int s, int e, int a) {
  if (seg[a].rev == false) return;
  seg[a].rev = false;
  swap(seg[a].c[0], seg[a].c[1]);
  swap(seg[a].sb[0], seg[a].sb[1]);
  if (s != e) seg[2 * a].rev ^= 1, seg[2 * a + 1].rev ^= 1;
}
void st(int n) {
  seg[n].c[0] = seg[2 * n].c[0] + seg[2 * n + 1].c[0];
  seg[n].c[1] = seg[2 * n].c[1] + seg[2 * n + 1].c[1];
  seg[n].sb[0] = max(seg[2 * n].c[0] + seg[2 * n + 1].sb[0],
                     seg[2 * n].sb[0] + seg[2 * n + 1].c[1]);
  seg[n].sb[1] = max(seg[2 * n].c[1] + seg[2 * n + 1].sb[1],
                     seg[2 * n].sb[1] + seg[2 * n + 1].c[0]);
}
void make(int s, int e, int n) {
  seg[n].rev = false;
  if (s == e) {
    seg[n].sb[0] = seg[n].sb[1] = 1;
    if (inp[s] == '4')
      seg[n].c[0] = 1, seg[n].c[1] = 0;
    else
      seg[n].c[1] = 1, seg[n].c[0] = 0;
    return;
  }
  int m = (s + e) / 2;
  make(s, m, 2 * n);
  make(m + 1, e, 2 * n + 1);
  st(n);
}
void rev(int s, int e, int n, const int &bs, const int &be) {
  if (s > be || e < bs) return;
  if (s >= bs && e <= be) {
    seg[n].rev ^= 1;
    return;
  }
  fix(s, e, n);
  int m = (s + e) / 2;
  rev(s, m, 2 * n, bs, be);
  rev(m + 1, e, 2 * n + 1, bs, be);
  fix(s, m, 2 * n);
  fix(m + 1, e, 2 * n + 1);
  st(n);
}
int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin >> n >> m >> inp;
  make(0, n - 1, 1);
  for (int i = 0; i < m; i++) {
    string com;
    cin >> com;
    if (com[0] == 'c') {
      fix(0, n - 1, 1);
      cout << seg[1].sb[0] << '\n';
      continue;
    }
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    rev(0, n - 1, 1, a, b);
  }
  return 0;
}
