#include <bits/stdc++.h>
using namespace std;
struct Node {
  bool lz;
  int n4, n7, n47, n74;
  Node(int n4 = 0, int n7 = 0, int n47 = 0, int n74 = 0, bool lz = false) {
    this->n4 = n4;
    this->n7 = n7;
    this->n47 = n47;
    this->n74 = n74;
    this->lz = lz;
  }
};
struct SegmentTree {
  int n;
  vector<Node> tree;
  SegmentTree(int n) {
    this->n = n;
    tree.resize(4 * n);
  }
  void build(string &a, int c, int s, int e) {
    if (s == e) {
      tree[c].n4 = (a[s] == '4');
      tree[c].n7 = (a[e] == '7');
      tree[c].n47 = tree[c].n74 = 1;
      return;
    }
    int m = (s + e) / 2;
    build(a, 2 * c, s, m);
    build(a, 2 * c + 1, m + 1, e);
    tree[c].n4 = tree[2 * c].n4 + tree[2 * c + 1].n4;
    tree[c].n7 = tree[2 * c].n7 + tree[2 * c + 1].n7;
    tree[c].n47 = max(tree[2 * c].n47 + tree[2 * c + 1].n7,
                      tree[2 * c].n4 + tree[2 * c + 1].n47);
    tree[c].n74 = max(tree[2 * c].n7 + tree[2 * c + 1].n74,
                      tree[2 * c].n74 + tree[2 * c + 1].n4);
  }
  void update(int c, int s, int e, int l, int r) {
    if (tree[c].lz) {
      swap(tree[c].n4, tree[c].n7);
      swap(tree[c].n47, tree[c].n74);
      if (s != e) {
        tree[2 * c].lz ^= true;
        tree[2 * c + 1].lz ^= true;
      }
      tree[c].lz = false;
    }
    if (s > e or s > r or e < l) {
      return;
    }
    if (s >= l and e <= r) {
      swap(tree[c].n4, tree[c].n7);
      swap(tree[c].n47, tree[c].n74);
      if (s != e) {
        tree[2 * c].lz ^= true;
        tree[2 * c + 1].lz ^= true;
      }
      return;
    }
    int m = (s + e) / 2;
    update(2 * c, s, m, l, r);
    update(2 * c + 1, m + 1, e, l, r);
    tree[c].n4 = tree[2 * c].n4 + tree[2 * c + 1].n4;
    tree[c].n7 = tree[2 * c].n7 + tree[2 * c + 1].n7;
    tree[c].n47 = max(tree[2 * c].n47 + tree[2 * c + 1].n7,
                      tree[2 * c].n4 + tree[2 * c + 1].n47);
    tree[c].n74 = max(tree[2 * c].n7 + tree[2 * c + 1].n74,
                      tree[2 * c].n74 + tree[2 * c + 1].n4);
  }
  Node query(int c, int s, int e, int l, int r) {
    if (tree[c].lz) {
      swap(tree[c].n4, tree[c].n7);
      swap(tree[c].n47, tree[c].n74);
      if (s != e) {
        tree[2 * c].lz ^= true;
        tree[2 * c + 1].lz ^= true;
      }
      tree[c].lz = false;
    }
    if (s > e or s > r or e < l) {
      return Node();
    }
    if (s >= l and e <= r) {
      return tree[c];
    }
    int m = (s + e) / 2;
    Node lc = query(2 * c, s, m, l, r);
    Node rc = query(2 * c + 1, m + 1, e, l, r);
    Node res;
    res.n4 = lc.n4 + rc.n4;
    res.n7 = lc.n7 + rc.n7;
    res.n47 = max(lc.n47 + rc.n7, lc.n4 + rc.n47);
    res.n74 = max(lc.n7 + rc.n74, lc.n74 + rc.n4);
    return res;
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, q;
  cin >> n >> q;
  string a;
  cin >> a;
  SegmentTree s(n);
  s.build(a, 1, 0, n - 1);
  while (q--) {
    string t;
    cin >> t;
    if (t == "count") {
      cout << s.query(1, 0, n - 1, 0, n - 1).n47 << '\n';
    } else {
      int l, r;
      cin >> l >> r;
      s.update(1, 0, n - 1, l - 1, r - 1);
    }
  }
}
