#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64777216")
using namespace std;
template <typename T>
int size(T &a) {
  return (int)a.size();
}
template <typename T>
T sqr(T a) {
  return a * a;
}
struct elem {
  bool rev;
  int cnt0, cnt1, best, bestInv;
  elem() {}
  void Swap() {
    swap(cnt0, cnt1);
    swap(best, bestInv);
  }
};
const int MAXT = 1000000;
elem f[4 * MAXT + 1];
int l[4 * MAXT + 1], r[4 * MAXT + 1];
int sz = 1;
int calc(int best1, int best2, int c0, int c1) {
  return max(c0 + best2, best1 + c1);
}
int calcW1(int abw1, int bbw1, int a0, int b1) {
  return max(abw1 + b1, a0 + bbw1);
}
elem merge(elem a, elem b) {
  elem ret;
  ret.rev = false;
  ret.cnt0 = a.cnt0 + b.cnt0;
  ret.cnt1 = a.cnt1 + b.cnt1;
  ret.best = calc(a.best, b.best, a.cnt0, b.cnt1);
  ret.bestInv = calc(a.bestInv, b.bestInv, a.cnt1, b.cnt0);
  return ret;
}
void push(int v) {
  if (f[v].rev) {
    f[v].rev = false;
    f[v].Swap();
    if (2 * v < 4 * MAXT + 1) {
      f[2 * v].rev ^= true;
    }
    if (2 * v + 1 < 4 * MAXT + 1) {
      f[2 * v + 1].rev ^= true;
    }
  }
}
int a[MAXT];
void build(int l, int r, int u) {
  ::l[u] = l;
  ::r[u] = r;
  ++sz;
  if (l == r) {
    elem &e = f[u];
    e.best = e.bestInv = 1;
    e.cnt0 = (a[l] == 0);
    e.cnt1 = (a[l] == 1);
    e.rev = false;
  } else {
    build(l, (l + r) / 2, 2 * u);
    build((l + r) / 2 + 1, r, 2 * u + 1);
    f[u] = merge(f[2 * u], f[2 * u + 1]);
  }
}
void change(int lf, int rg, int u) {
  push(u);
  if (lf > r[u] || rg < l[u]) return;
  if (lf <= l[u] && r[u] <= rg) {
    f[u].rev = true;
    push(u);
  } else {
    change(lf, rg, 2 * u);
    change(lf, rg, 2 * u + 1);
    f[u] = merge(f[2 * u], f[2 * u + 1]);
  }
}
char buf[1 << 10], s[1000100];
char x[1 << 10];
int main() {
  int n, m;
  gets(buf);
  sscanf(buf, "%d%d", &n, &m);
  gets(s);
  for (int i = (0); i < (n); ++i) a[i] = (s[i] == '4' ? 0 : 1);
  build(0, n - 1, 1);
  for (int i = (0); i < (m); ++i) {
    gets(buf);
    if (buf[0] == 'c') {
      printf("%d\n", f[1].best);
    } else {
      int l, r;
      sscanf(buf, "%s %d%d", x, &l, &r);
      --l, --r;
      change(l, r, 1);
    }
  }
}
