#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 6;
struct node {
  int longest00, longest01, longest10, longest11;
};
node tree[4 * MAXN];
bool lazy[4 * MAXN];
bool b[MAXN];
node merge(node n1, node n2) {
  node ret;
  ret.longest00 = n1.longest00 + n2.longest00;
  ret.longest11 = n1.longest11 + n2.longest11;
  ret.longest10 =
      max(max(n1.longest11 + n2.longest10, n1.longest11 + n2.longest00),
          n1.longest10 + n2.longest00);
  ret.longest01 =
      max(max(n1.longest00 + n2.longest01, n1.longest00 + n2.longest11),
          n1.longest01 + n2.longest11);
  return ret;
}
void reverse(int l, int r, int idx) {
  int l00 = tree[idx].longest00;
  int l10 = tree[idx].longest10;
  int l01 = tree[idx].longest01;
  int l11 = tree[idx].longest11;
  tree[idx].longest00 = l11;
  tree[idx].longest11 = l00;
  tree[idx].longest01 = l10;
  tree[idx].longest10 = l01;
}
void push(int l, int r, int idx) {
  if (lazy[idx] == 0) return;
  reverse(l, r, idx);
  if (l != r) {
    lazy[idx * 2] ^= 1;
    lazy[idx * 2 + 1] ^= 1;
  }
  lazy[idx] = 0;
}
void update(int l, int r, int idx, int ql, int qr, bool val) {
  if (l > r) return;
  push(l, r, idx);
  if (l > qr) return;
  if (r < ql) return;
  if (l >= ql && r <= qr) {
    lazy[idx] ^= val;
    push(l, r, idx);
    return;
  }
  int mid = (l + r) / 2;
  update(l, mid, idx * 2, ql, qr, val);
  update(mid + 1, r, idx * 2 + 1, ql, qr, val);
  tree[idx] = merge(tree[idx * 2], tree[idx * 2 + 1]);
}
node query(int l, int r, int idx, int ql, int qr) {
  if (l > r) return {0, 0, 0, 0};
  push(l, r, idx);
  if (l > qr) return {0, 0, 0, 0};
  if (r < ql) return {0, 0, 0, 0};
  if (l >= ql && r <= qr) {
    return tree[idx];
  }
  int mid = (l + r) / 2;
  return merge(query(l, mid, idx * 2, ql, qr),
               query(mid + 1, r, idx * 2 + 1, ql, qr));
}
void build(int l, int r, int idx) {
  if (l > r) return;
  tree[idx] = {0, 0, 0, 0};
  lazy[idx] = 0;
  if (l == r) {
    if (b[l] == 1)
      tree[idx].longest11 = 1;
    else
      tree[idx].longest00 = 1;
    return;
  }
  int mid = (l + r) / 2;
  build(l, mid, idx * 2);
  build(mid + 1, r, idx * 2 + 1);
  tree[idx] = merge(tree[idx * 2], tree[idx * 2 + 1]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, q;
  cin >> n >> q;
  for (int i = 1; i <= n; ++i) {
    char c;
    cin >> c;
    if (c == '4')
      b[i] = 0;
    else
      b[i] = 1;
  }
  build(1, n, 1);
  for (int i = 0; i < q; ++i) {
    string command;
    cin >> command;
    if (command == "count") {
      node t = query(1, n, 1, 1, n);
      cout << max(t.longest00, max(t.longest01, t.longest11)) << endl;
    } else {
      int l, r;
      cin >> l >> r;
      update(1, n, 1, l, r, 1);
    }
  }
  return 0;
}
