#include <bits/stdc++.h>
using namespace std;
const int maxn = 1 << 21;
int n, m;
char s[maxn];
char cmd[maxn];
struct lucky {
  int c4, c7, c47, c74;
  lucky() { c4 = 0, c7 = 0, c47 = 0, c74 = 0; }
  void merge(lucky a, lucky b) {
    c4 = a.c4 + b.c4;
    c7 = a.c7 + b.c7;
    c47 = max(a.c47 + b.c7, a.c4 + b.c47);
    c74 = max(a.c74 + b.c4, a.c7 + b.c74);
  }
  void reset(char c) {
    if (c == '7')
      c7 = 1;
    else
      c4 = 1;
    c47 = 1;
    c74 = 1;
  }
  void chng() {
    swap(c4, c7);
    swap(c47, c74);
  }
  void recieve(bool bb) {
    if (bb) chng();
  }
};
lucky seg[maxn];
bool lazy[maxn];
lucky build(int rt, int lp, int rp) {
  if (lp + 1 == rp) {
    seg[rt].reset(s[lp]);
  } else {
    int mid = (lp + rp) / 2;
    seg[rt].merge(build(rt * 2, lp, mid), build(rt * 2 + 1, mid, rp));
  }
  return seg[rt];
}
int qa, qb;
lucky update(int rt, int lp, int rp) {
  if (lp >= qb || rp <= qa) return seg[rt];
  if (qa <= lp && rp <= qb) {
    lazy[rt] ^= true;
    seg[rt].chng();
  } else {
    int mid = (lp + rp) / 2;
    seg[rt].merge(update(rt * 2, lp, mid), update(rt * 2 + 1, mid, rp));
    seg[rt].recieve(lazy[rt]);
  }
  return seg[rt];
}
int main() {
  scanf("%d%d%s", &n, &m, s);
  build(1, 0, n);
  for (int i = 0; i < m; i++) {
    scanf("%s", cmd);
    if (cmd[0] == 'c') {
      printf("%d\n", seg[1].c47);
    } else {
      scanf("%d%d", &qa, &qb);
      qa--;
      update(1, 0, n);
    }
  }
}
