#include <bits/stdc++.h>
using namespace std;
struct node {
  int cnt[2], sec[2];
};
int a[1000005];
vector<node> seg(4 * 1000005);
int lazy[4 * 1000005];
node merge(node a, node b) {
  node t;
  for (long long int i = 0; i < 2; i++) {
    t.cnt[i] = a.cnt[i] + b.cnt[i];
    t.sec[i] = max(a.cnt[i] + b.cnt[1 - i],
                   max(a.sec[i] + b.cnt[1 - i], a.cnt[i] + b.sec[i]));
  }
  return t;
}
void build(int cur, int st, int en) {
  if (st == en) {
    node t;
    if (a[st] == 4) {
      t.cnt[0] = t.sec[0] = t.sec[1] = 1;
      t.cnt[1] = 0;
    } else {
      t.cnt[1] = t.sec[0] = t.sec[1] = 1;
      t.cnt[0] = 0;
    }
    seg[cur] = t;
    return;
  }
  int mid = (st + en) / 2;
  build(2 * cur, st, mid);
  build(2 * cur + 1, mid + 1, en);
  seg[cur] = merge(seg[2 * cur], seg[2 * cur + 1]);
}
void push(int cur) {
  if (lazy[cur] % 2) {
    lazy[2 * cur] += lazy[cur];
    lazy[2 * cur + 1] += lazy[cur];
    for (long long int i = 0; i < 2; i++) {
      swap(seg[2 * cur + i].cnt[i], seg[2 * cur + i].cnt[1 - i]);
      swap(seg[2 * cur + i].sec[i], seg[2 * cur + i].sec[1 - i]);
    }
    lazy[cur] = 0;
  }
}
void update(int cur, int st, int en, int l, int r) {
  if (r < st or l > en) return;
  if (l <= st and en <= r) {
    lazy[cur]++;
    swap(seg[cur].cnt[0], seg[cur].cnt[1]);
    swap(seg[cur].sec[0], seg[cur].sec[1]);
    return;
  }
  push(cur);
  int mid = (st + en) / 2;
  update(2 * cur, st, mid, l, r);
  update(2 * cur + 1, mid + 1, en, l, r);
  seg[cur] = merge(seg[2 * cur], seg[2 * cur + 1]);
}
void solve() {
  int n, m;
  cin >> n >> m;
  string s;
  cin >> s;
  for (long long int i = 1; i < n + 1; i++) a[i] = s[i - 1] - '0';
  build(1, 1, n);
  while (m--) {
    string s;
    cin >> s;
    if (s == "count") {
      cout << seg[1].sec[0] << '\n';
    } else {
      int l, r;
      cin >> l >> r;
      update(1, 1, n, l, r);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) {
    solve();
  }
  return 0;
}
