#include <bits/stdc++.h>
using namespace std;
char str[1000005];
int N, M;
int xr[1000005 << 2];
int s4[1000005 << 2], s7[1000005 << 2], s47[1000005 << 2], s74[1000005 << 2];
void pushup(int rt) {
  s4[rt] = s4[rt << 1] + s4[rt << 1 | 1];
  s7[rt] = s7[rt << 1] + s7[rt << 1 | 1];
  s47[rt] = max(s47[rt << 1] + s7[rt << 1 | 1], s4[rt << 1] + s47[rt << 1 | 1]);
  s74[rt] = max(s74[rt << 1] + s4[rt << 1 | 1], s7[rt << 1] + s74[rt << 1 | 1]);
}
void pushdown(int rt) {
  if (xr[rt]) {
    xr[rt << 1] ^= xr[rt];
    xr[rt << 1 | 1] ^= xr[rt];
    swap(s4[rt << 1], s7[rt << 1]);
    swap(s4[rt << 1 | 1], s7[rt << 1 | 1]);
    swap(s47[rt << 1], s74[rt << 1]);
    swap(s47[rt << 1 | 1], s74[rt << 1 | 1]);
    xr[rt] = 0;
  }
}
void build(int l, int r, int rt) {
  int m = (l + r) >> 1;
  if (l == r) {
    s4[rt] = (str[l] == '4');
    s7[rt] = (str[l] == '7');
    s47[rt] = s74[rt] = 1;
    return;
  }
  build(l, m, rt << 1);
  build(m + 1, r, rt << 1 | 1);
  pushup(rt);
  xr[rt] = 0;
}
void insert(int L, int R, int l, int r, int rt) {
  int m = (l + r) >> 1;
  if (L <= l && r <= R) {
    xr[rt] ^= 1;
    swap(s4[rt], s7[rt]);
    swap(s47[rt], s74[rt]);
    return;
  }
  pushdown(rt);
  if (L <= m) insert(L, R, l, m, rt << 1);
  if (m < R) insert(L, R, m + 1, r, rt << 1 | 1);
  pushup(rt);
}
int main() {
  int i, j;
  while (scanf("%d%d%s", &N, &M, str + 1) != EOF) {
    build(1, N, 1);
    while (M--) {
      char op[10];
      scanf("%s", op);
      if (op[0] == 's') {
        int L, R;
        scanf("%d%d", &L, &R);
        insert(L, R, 1, N, 1);
      } else
        printf("%d\n", s47[1]);
    }
  }
  return 0;
}
