#include <bits/stdc++.h>
using namespace std;
int n, m, lazy[4 * 1000002], st[4 * 1000002], four[4 * 1000002],
    St[4 * 1000002];
char s[1000002];
void update(int nod, int l, int r, int pos, int val) {
  if (l > r || l > pos || r < pos) return;
  if (l == r) {
    st[nod] = 1;
    St[nod] = 1;
    if (val == 0)
      four[nod] = 1;
    else
      four[nod] = 0;
    return;
  }
  int mid = (l + r) >> 1, lson = 2 * nod, rson = lson + 1;
  if (pos <= mid)
    update(lson, l, mid, pos, val);
  else
    update(rson, mid + 1, r, pos, val);
  four[nod] = four[lson] + four[rson];
  st[nod] = max(four[lson] + st[rson], st[lson] + r - mid - four[rson]);
  St[nod] = max(mid - l + 1 - four[lson] + St[rson], St[lson] + four[rson]);
}
void lazy_update(int nod, int l, int r, int x, int y) {
  int mid = (l + r) >> 1, lson = 2 * nod, rson = lson + 1;
  if (lazy[nod]) {
    four[nod] = r - l + 1 - four[nod];
    if (l < r) {
      swap(st[nod], St[nod]);
      lazy[lson] ^= 1;
      lazy[rson] ^= 1;
    } else {
      st[nod] = St[nod] = 1;
    }
    lazy[nod] = 0;
  }
  if (l > r || l > y || r < x) return;
  if (x <= l && r <= y) {
    four[nod] = r - l + 1 - four[nod];
    if (l != r) {
      swap(st[nod], St[nod]);
      lazy[lson] ^= 1;
      lazy[rson] ^= 1;
    } else {
      st[nod] = St[nod] = 1;
    }
    return;
  }
  lazy_update(lson, l, mid, x, y);
  lazy_update(rson, mid + 1, r, x, y);
  four[nod] = four[lson] + four[rson];
  st[nod] = max(four[lson] + st[rson], st[lson] + r - mid - four[rson]);
  St[nod] = max(mid - l + 1 - four[lson] + St[rson], St[lson] + four[rson]);
}
void read() {
  scanf("%d %d\n", &n, &m);
  gets(s + 1);
}
void solve() {
  for (int i = 1; i <= n; ++i) {
    if (s[i] == '4')
      update(1, 1, n, i, 0);
    else
      update(1, 1, n, i, 1);
  }
}
void write() {
  while (m--) {
    gets(s + 1);
    if (s[1] == 'c')
      printf("%d\n", st[1]);
    else {
      int l = 0, r = 0, i = 8;
      int len = strlen(s + 1);
      while (s[i] >= '0' && s[i] <= '9' && i <= len) {
        l = l * 10 + s[i] - '0';
        ++i;
      }
      while (i <= len && (s[i] < '0' || s[i] > '9')) ++i;
      while (i <= len && s[i] >= '0' && s[i] <= '9') {
        r = r * 10 + s[i] - '0';
        ++i;
      }
      lazy_update(1, 1, n, l, r);
    }
  }
}
int main() {
  read();
  solve();
  write();
  return 0;
}
