#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const int INF = 1000 * 1000 * 1000;
const double EPS = 1e-9;
const int MAXN = 1001001;
char buf[MAXN];
int tree[MAXN << 2][4];
bool isReversed[MAXN << 2];
int N, Q;
void recalc(int v) {
  tree[v][0] = tree[v << 1][0] + tree[v << 1 | 1][0];
  tree[v][1] = tree[v << 1][1] + tree[v << 1 | 1][1];
  tree[v][2] = tree[v << 1][0] + tree[v << 1 | 1][1];
  tree[v][2] = max(tree[v][2], tree[v << 1][0] + tree[v << 1 | 1][2]);
  tree[v][2] = max(tree[v][2], tree[v << 1][2] + tree[v << 1 | 1][1]);
  tree[v][3] = tree[v << 1][1] + tree[v << 1 | 1][0];
  tree[v][3] = max(tree[v][3], tree[v << 1][1] + tree[v << 1 | 1][3]);
  tree[v][3] = max(tree[v][3], tree[v << 1][3] + tree[v << 1 | 1][0]);
}
void push(int v, bool isLeaf) {
  if (isReversed[v]) {
    isReversed[v] = false;
    swap(tree[v][0], tree[v][1]);
    swap(tree[v][2], tree[v][3]);
    if (!isLeaf) {
      isReversed[v << 1] ^= true;
      isReversed[v << 1 | 1] ^= true;
    }
  }
}
void buildTree(int v = 1, int tl = 0, int tr = N - 1) {
  if (tl == tr) {
    tree[v][0] = buf[tl] == '4';
    tree[v][1] = buf[tl] == '7';
    tree[v][2] = tree[v][3] = 1;
    return;
  }
  int tm = (tl + tr) >> 1;
  buildTree(v << 1, tl, tm);
  buildTree(v << 1 | 1, tm + 1, tr);
  recalc(v);
}
void doSwitch(int l, int r, int v = 1, int tl = 0, int tr = N - 1) {
  push(v, tl == tr);
  if (l == tl && r == tr) {
    isReversed[v] ^= true;
    push(v, tl == tr);
    return;
  }
  int tm = (tl + tr) >> 1;
  if (r <= tm) {
    push(v << 1 | 1, (tm + 1) == tr);
    doSwitch(l, r, v << 1, tl, tm);
  } else if (l > tm) {
    push(v << 1, tl == tm);
    doSwitch(l, r, v << 1 | 1, tm + 1, tr);
  } else {
    doSwitch(l, tm, v << 1, tl, tm);
    doSwitch(tm + 1, r, v << 1 | 1, tm + 1, tr);
  }
  recalc(v);
}
int doCount() { return tree[1][2]; }
int main() {
  scanf("%d%d", &N, &Q);
  scanf("%s", buf);
  buildTree();
  while (Q--) {
    char cmd[1 << 4];
    scanf("%s", cmd);
    if (cmd[0] == 'c') {
      printf("%d\n", doCount());
    } else {
      int l, r;
      scanf("%d%d", &l, &r);
      doSwitch(l - 1, r - 1);
    }
  }
  return 0;
}
