#include <bits/stdc++.h>
using namespace std;
void read(int &k) {
  k = 0;
  char x = getchar();
  while (x < '0' || x > '9') x = getchar();
  while (x >= '0' && x <= '9') {
    k = k * 10 - 48 + x;
    x = getchar();
  }
}
int n, m, x, y;
char s[1200010];
struct node {
  int rev, c[2][2];
  node() {
    rev = 0;
    c[0][0] = c[0][1] = c[1][0] = c[1][1] = 0;
  }
  void init(int k) { c[k][k] = 1; }
};
node join(node &a, node &b) {
  node ret;
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < 2; j++)
      for (int p = 0; p < 2; p++)
        for (int q = 0; q < 2; q++)
          if ((i <= j && j <= p && p <= q) || (i >= j && j >= p && p >= q))
            ret.c[i][q] = max(ret.c[i][q], a.c[i][j] + b.c[p][q]);
  return ret;
}
struct SegmentTree {
  node c[4000010];
  void maketree(int L, int R, int now) {
    if (L == R) {
      c[now].init(s[L] == '7');
      return;
    }
    int t = (L + R) / 2;
    maketree(L, t, now * 2);
    maketree(t + 1, R, now * 2 + 1);
    c[now] = join(c[now * 2], c[now * 2 + 1]);
  }
  int solve() {
    update(1);
    return max(max(c[1].c[0][1], c[1].c[1][1]), c[1].c[0][0]);
  }
  void update(int now) {
    if (!c[now].rev) return;
    swap(c[now].c[0][1], c[now].c[1][0]);
    swap(c[now].c[0][0], c[now].c[1][1]);
    if (now <= 2000000) c[now * 2].rev ^= 1, c[now * 2 + 1].rev ^= 1;
    c[now].rev = 0;
  }
  void modify(int L, int R, int l, int r, int now) {
    update(now);
    if (L == l && R == r) {
      c[now].rev = 1;
      return;
    }
    int t = (L + R) / 2;
    if (r <= t)
      modify(L, t, l, r, now * 2);
    else if (l > t)
      modify(t + 1, R, l, r, now * 2 + 1);
    else
      modify(L, t, l, t, now * 2), modify(t + 1, R, t + 1, r, now * 2 + 1);
    update(now * 2);
    update(now * 2 + 1);
    c[now] = join(c[now * 2], c[now * 2 + 1]);
  }
} xds;
int main() {
  read(n);
  read(m);
  scanf("%s", s + 1);
  xds.maketree(1, n, 1);
  for (; m--;) {
    scanf("%s", s);
    if (s[0] == 'c')
      printf("%d\n", xds.solve());
    else {
      read(x);
      read(y);
      xds.modify(1, n, x, y, 1);
    }
  }
  return 0;
}
