#include <bits/stdc++.h>
using namespace std;
int n, m;
char cmd[10];
char s[1000010];
struct Node {
  int mx, mxRev, fours, sevens;
  Node() { mx = mxRev = fours = sevens = 0; }
};
Node st[4000010];
bool lazy[4000010];
void merge(int i) {
  int lf = i << 1, rg = lf | 1;
  st[i].mx = max(st[lf].mx + st[rg].sevens, st[lf].fours + st[rg].mx);
  st[i].mxRev = max(st[lf].mxRev + st[rg].fours, st[lf].sevens + st[rg].mxRev);
  st[i].fours = st[lf].fours + st[rg].fours;
  st[i].sevens = st[lf].sevens + st[rg].sevens;
}
void build(int l, int r, int i) {
  if (l > r) return;
  if (l == r) {
    if (s[l] == '4')
      st[i].fours = 1;
    else
      st[i].sevens = 1;
    st[i].mx = st[i].mxRev = 1;
    return;
  }
  int m = (l + r) >> 1;
  build(l, m, i << 1);
  build(m + 1, r, 1 + (i << 1));
  merge(i);
}
void push_down(int l, int r, int i) {
  if (lazy[i]) {
    if (l != r) {
      lazy[i << 1] ^= 1;
      lazy[1 + (i << 1)] ^= 1;
    }
    swap(st[i].mx, st[i].mxRev);
    swap(st[i].fours, st[i].sevens);
  }
  lazy[i] = false;
}
void update(int l, int r, int ls, int rs, int i) {
  push_down(l, r, i);
  if (r < ls || rs < l) return;
  if (ls <= l && r <= rs) {
    lazy[i] ^= 1;
    push_down(l, r, i);
    return;
  }
  int m = (l + r) >> 1;
  update(l, m, ls, rs, i << 1);
  update(m + 1, r, ls, rs, 1 + (i << 1));
  merge(i);
}
int main() {
  scanf("%d%d", &n, &m);
  scanf(" %s", s + 1);
  build(1, n, 1);
  while (m--) {
    scanf(" %s", cmd);
    if (cmd[0] == 'c') {
      printf("%d\n", st[1].mx);
    } else {
      int l, r;
      scanf("%d%d", &l, &r);
      update(1, n, l, r, 1);
    }
  }
  return 0;
}
