#include <bits/stdc++.h>
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int N = 1e6 + 6, M = 1e9 + 7;
struct node {
  int inc, dec, c4, c7;
};
int h, n, d[N];
node t[2 * N];
node combine(node l, node r) {
  node res;
  res.inc = max(l.inc + r.c7, r.inc + l.c4);
  res.dec = max(l.dec + r.c4, r.dec + l.c7);
  res.c4 = l.c4 + r.c4;
  res.c7 = l.c7 + r.c7;
  return res;
}
void calc(int p, int k) {
  if (!d[p])
    t[p] = combine(t[p << 1], t[p << 1 | 1]);
  else
    swap(t[p].inc, t[p].dec), swap(t[p].c4, t[p].c7);
}
void apply(int p, int value, int k) {
  swap(t[p].inc, t[p].dec);
  swap(t[p].c4, t[p].c7);
  if (p < n) d[p] ^= 1;
}
void build() {
  for (int i = n - 1; i > 0; --i) t[i] = combine(t[i << 1], t[i << 1 | 1]);
}
void push(int l, int r) {
  int s = h, k = 1 << (h - 1);
  for (l += n, r += n - 1; s > 0; --s, k >>= 1)
    for (int i = l >> s; i <= r >> s; ++i)
      if (d[i]) {
        apply(i << 1, d[i], k);
        apply(i << 1 | 1, d[i], k);
        d[i] = 0;
      }
}
void update(int l, int r, int value = 0) {
  push(l, l + 1);
  push(r - 1, r);
  bool cl = false, cr = false;
  int k = 1;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1, k <<= 1) {
    if (cl) calc(l - 1, k);
    if (cr) calc(r, k);
    if (l & 1) apply(l++, value, k), cl = true;
    if (r & 1) apply(--r, value, k), cr = true;
  }
  for (--l; r > 0; l >>= 1, r >>= 1, k <<= 1) {
    if (cl) calc(l, k);
    if (cr && (!cl || l != r)) calc(r, k);
  }
}
node query(int l, int r) {
  push(l, l + 1);
  push(r - 1, r);
  node resl, resr;
  resl = resr = {0, 0, 0, 0};
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) resl = combine(resl, t[l++]);
    if (r & 1) resr = combine(t[--r], resr);
  }
  return combine(resl, resr);
}
int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr);
  int q;
  string s;
  cin >> n >> q >> s;
  h = sizeof(int) * 8 - __builtin_clz(n);
  for (int i = 0; i < n; i++) {
    int x = s[i] == '4';
    t[n + i] = {1, 1, x, !x};
  }
  build();
  while (q--) {
    cin >> s;
    if (s == "count")
      cout << query(0, n).inc << '\n';
    else {
      int l, r;
      cin >> l >> r;
      update(l - 1, r);
    }
  }
}
