#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e6 + 10, step = 442, len = N / 440;
char s2[N], z[90];
int s[N], sw[len], sum[len][2], ans[len][2], l[len], r[len];
void calc(int l, int r, int &a, int &b, int &sum1, int &sum0, int w) {
  a = b = sum1 = sum0 = 0;
  int *ss = s + l;
  for (int i = r - l; i >= 0; --i) sum1 += *(ss++) ^= w;
  sum0 = r - l + 1 - sum1;
  ss = s + l;
  int a1 = sum1, a0 = sum0;
  for (int i = r - l; i >= 0; --i) {
    a1 -= *ss;
    a0 -= (*ss) ^ 1;
    a1++, a0++;
    if (a < a1) a = a1;
    if (b < a0) b = a0;
    a1 -= *ss;
    a0 -= (*(ss++)) ^ 1;
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  scanf(" %s", s2);
  for (int i = 0; i < n; ++i) s[i] = s2[i] != '4';
  memset(l, -1, sizeof l);
  for (int i = 0, j = 0;; i += step, j++) {
    l[j] = i;
    r[j] = min(i + step - 1, n - 1);
    calc(l[j], r[j], ans[j][0], ans[j][1], sum[j][0], sum[j][1], 0);
    if (r[j] == n - 1) break;
  }
  for (int _ = 0; _ < m; ++_) {
    scanf(" %s", z);
    if (z[0] == 'c') {
      int best = 0;
      int s0 = 0, s1 = 0;
      for (int j = 0; l[j] != -1; j++) s1 += sum[j][sw[j]];
      for (int j = 0; l[j] != -1; j++) {
        s1 -= sum[j][sw[j]];
        best = max(best, ans[j][sw[j]] + s1 + s0);
        s0 += sum[j][sw[j] ^ 1];
      }
      printf("%d\n", best);
    } else {
      int left, right;
      scanf("%d %d", &left, &right);
      left--, right--;
      for (int j = 0; l[j] != -1; j++) {
        if (r[j] < left) continue;
        if (l[j] > right) break;
        if (l[j] >= left && r[j] <= right) {
          sw[j] ^= 1;
          continue;
        }
        int rr = min(r[j], right), ll = max(l[j], left);
        int *ss = s + ll;
        for (int i = rr - ll; i >= 0; --i) *(ss++) ^= 1;
        calc(l[j], r[j], ans[j][0], ans[j][1], sum[j][0], sum[j][1], sw[j]);
        sw[j] = 0;
      }
    }
  }
  return 0;
}
