#include <bits/stdc++.h>
using namespace std;
char s[1000005];
int n, m, col[1000005 << 2];
int c4[1000005 << 2], c7[1000005 << 2], c47[1000005 << 2], c74[1000005 << 2];
void update(int rt) {
  c4[rt] = c4[rt << 1] + c4[rt << 1 | 1];
  c7[rt] = c7[rt << 1] + c7[rt << 1 | 1];
  c47[rt] = max(c47[rt << 1] + c7[rt << 1 | 1], c4[rt << 1] + c47[rt << 1 | 1]);
  c74[rt] = max(c74[rt << 1] + c4[rt << 1 | 1], c7[rt << 1] + c74[rt << 1 | 1]);
}
void pushdown(int rt) {
  if (col[rt]) {
    col[rt << 1] ^= col[rt];
    col[rt << 1 | 1] ^= col[rt];
    swap(c4[rt << 1], c7[rt << 1]);
    swap(c4[rt << 1 | 1], c7[rt << 1 | 1]);
    swap(c47[rt << 1], c74[rt << 1]);
    swap(c47[rt << 1 | 1], c74[rt << 1 | 1]);
    col[rt] = 0;
  }
}
void build(int rt, int l, int r) {
  int m = l + r >> 1;
  col[rt] = 0;
  if (l == r) {
    c4[rt] = (s[l] == '4');
    c7[rt] = (s[l] == '7');
    c47[rt] = c74[rt] = 1;
    return;
  }
  build(rt << 1, l, m);
  build(rt << 1 | 1, m + 1, r);
  update(rt);
}
void flip(int L, int R, int rt, int l, int r) {
  int m = l + r >> 1;
  if (L <= l && r <= R) {
    col[rt] ^= 1;
    swap(c4[rt], c7[rt]);
    swap(c47[rt], c74[rt]);
    return;
  }
  pushdown(rt);
  if (L <= m) flip(L, R, rt << 1, l, m);
  if (m < R) flip(L, R, rt << 1 | 1, m + 1, r);
  update(rt);
}
int main() {
  scanf("%d%d%s", &n, &m, s + 1);
  build(1, 1, n);
  while (m--) {
    scanf("%s", s);
    if (s[0] == 'c')
      printf("%d\n", c47[1]);
    else {
      int L, R;
      scanf("%d%d", &L, &R);
      flip(L, R, 1, 1, n);
    }
  }
  return 0;
}
