#include <bits/stdc++.h>
using namespace std;
const int maxN = 1000000 + 10;
string s;
int n, m;
struct Node {
  bool flag;
  int cnt4, cnt7, inc, dec;
};
struct Segment_Tree {
  Node tree[3 * maxN];
  void UPD(int v) {
    tree[v].cnt4 = tree[2 * v].cnt4 + tree[2 * v + 1].cnt4;
    tree[v].cnt7 = tree[2 * v].cnt7 + tree[2 * v + 1].cnt7;
    tree[v].inc = max(tree[2 * v].cnt4 + tree[2 * v + 1].inc,
                      tree[2 * v].inc + tree[2 * v + 1].cnt7);
    tree[v].dec = max(tree[2 * v].cnt7 + tree[2 * v + 1].dec,
                      tree[2 * v].dec + tree[2 * v + 1].cnt4);
  }
  void build(int v, int L, int R) {
    if (L == R) {
      if (s[L - 1] == '4')
        tree[v].cnt4 = 1;
      else
        tree[v].cnt7 = 1;
      tree[v].inc = tree[v].dec = 1;
      return;
    }
    int mid = (L + R) >> 1;
    build(2 * v, L, mid);
    build(2 * v + 1, mid + 1, R);
    UPD(v);
  }
  void update(int v, int L, int R, int l, int r) {
    if (l > r) return;
    if (L == l && R == r) {
      tree[v].cnt4 = R - L + 1 - tree[v].cnt4;
      tree[v].cnt7 = R - L + 1 - tree[v].cnt7;
      swap(tree[v].inc, tree[v].dec);
      tree[v].flag ^= 1;
      return;
    }
    int mid = (L + R) >> 1;
    if (tree[v].flag) {
      tree[v].flag = 0;
      tree[2 * v].flag ^= 1;
      tree[2 * v].cnt4 = mid - L + 1 - tree[2 * v].cnt4;
      tree[2 * v].cnt7 = mid - L + 1 - tree[2 * v].cnt7;
      swap(tree[2 * v].inc, tree[2 * v].dec);
      tree[2 * v + 1].flag ^= 1;
      tree[2 * v + 1].cnt4 = R - mid - tree[2 * v + 1].cnt4;
      tree[2 * v + 1].cnt7 = R - mid - tree[2 * v + 1].cnt7;
      swap(tree[2 * v + 1].inc, tree[2 * v + 1].dec);
    }
    update(2 * v, L, mid, l, min(r, mid));
    update(2 * v + 1, mid + 1, R, max(l, mid + 1), r);
    UPD(v);
  }
} A;
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m >> s;
  A.build(1, 1, n);
  while (m--) {
    string c;
    cin >> c;
    if (c == "count")
      cout << A.tree[1].inc << endl;
    else {
      int l, r;
      cin >> l >> r;
      A.update(1, 1, n, l, r);
    }
  }
  return 0;
}
