#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 1;
int n, m;
bool a[N];
array<int, 4> t[4 * N];
int d[4 * N];
array<int, 4> merge(const array<int, 4>& a, const array<int, 4>& b) {
  array<int, 4> c;
  c[0] = a[0] + b[0];
  c[1] = max(a[0] + b[1], a[1] + b[3]);
  c[2] = max(a[3] + b[2], a[2] + b[0]);
  c[3] = a[3] + b[3];
  return c;
}
void update(int q) { t[q] = merge(t[2 * q + 1], t[2 * q + 2]); }
void apply(int q) {
  d[q] ^= 1;
  swap(t[q][0], t[q][3]);
  swap(t[q][1], t[q][2]);
}
void push(int q) {
  if (!d[q]) return;
  apply(2 * q + 1);
  apply(2 * q + 2);
  d[q] = 0;
}
void build(int l, int r, int q) {
  if (l + 1 == r) {
    t[q][0] = a[l];
    t[q][3] = !a[l];
    t[q][1] = t[q][2] = 1;
    return;
  }
  int m = (l + r) / 2;
  build(l, m, 2 * q + 1);
  build(m, r, 2 * q + 2);
  update(q);
}
void change(int from, int to, int l, int r, int q) {
  if (from <= l && r <= to) {
    apply(q);
    return;
  }
  push(q);
  int m = (l + r) / 2;
  if (from < m) change(from, to, l, m, 2 * q + 1);
  if (to > m) change(from, to, m, r, 2 * q + 2);
  update(q);
}
int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    char c;
    cin >> c;
    a[i] = c == '4';
  }
  build(0, n, 0);
  while (m--) {
    string op;
    cin >> op;
    if (op == "count")
      cout << t[0][1] << '\n';
    else {
      int l, r;
      cin >> l >> r;
      --l;
      change(l, r, 0, n, 0);
    }
  }
}
