#include <bits/stdc++.h>
using namespace std;
long long P = 1e9 + 7;
long long P1 = 1e9 + 9;
const int sqr = 500;
const int arrn = 4e6 + 5;
const int arrn2 = 6e3 + 5;
vector<pair<int, pair<int, int>>> segtree(arrn);
bool marked[arrn] = {};
void inver(pair<int, pair<int, int>> &val) {
  val.first = -val.first;
  val.second.first = -val.second.first;
  val.second.second = -val.second.second;
  swap(val.second.first, val.second.second);
}
void push(int i) {
  if (marked[i]) {
    inver(segtree[i << 1]);
    inver(segtree[(i << 1) + 1]);
    marked[i << 1] = 1 - marked[i << 1];
    marked[(i << 1) + 1] = 1 - marked[(i << 1) + 1];
    marked[i] = 1 - marked[i];
  }
}
void update(int i) {
  segtree[i].first = segtree[i << 1].first + segtree[(i << 1) + 1].first;
  segtree[i].second.first =
      max(segtree[i << 1].second.first,
          segtree[i << 1].first + segtree[(i << 1) + 1].second.first);
  segtree[i].second.second =
      min(segtree[i << 1].second.second,
          segtree[i << 1].first + segtree[(i << 1) + 1].second.second);
}
void up(int i, int tl, int tr, int l, int r) {
  if (l > r) return;
  if (tl == l && tr == r) {
    marked[i] = 1 - marked[i];
    inver(segtree[i]);
    return;
  }
  int tm = (tl + tr) >> 1;
  push(i);
  up(i << 1, tl, tm, l, min(r, tm));
  up((i << 1) + 1, tm + 1, tr, max(tm + 1, l), r);
  update(i);
}
void preup(int i, int tl, int tr, vector<int> &pre) {
  if (tl == tr) {
    segtree[i].first = pre[tl];
    segtree[i].second.first = pre[tl];
    segtree[i].second.second = pre[tl];
    return;
  }
  int tm = (tl + tr) >> 1;
  push(i);
  preup(i << 1, tl, tm, pre);
  preup((i << 1) + 1, tm + 1, tr, pre);
  update(i);
}
void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> in(n);
  for (int i = 0; i < n; i++) {
    char k;
    cin >> k;
    in[i] = 2 * (k == '4') - 1;
  }
  preup(1, 0, n - 1, in);
  while (m--) {
    string typ;
    cin >> typ;
    if (typ == "count") {
      int oncnt = (n - segtree[1].first) / 2;
      int ans = segtree[1].second.first + oncnt;
      ans = max(ans, max(oncnt, n - oncnt));
      cout << ans << '\n';
    } else {
      int l, r;
      cin >> l >> r;
      l--;
      r--;
      up(1, 0, n - 1, l, r);
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
