#include <bits/stdc++.h>
using namespace std;
struct node {
  int no_4;
  int no_7;
  int no_47;
  int no_74;
  int prop;
  node(int a = 0, int b = 0, int c = 0, int d = 0, int e = 0)
      : no_47(c), no_4(a), no_74(d), no_7(b), prop(e) {}
};
int n;
node tree[4 * 1000005];
inline int max(int a, int b, int c) { return max(a, max(b, c)); }
inline node func(node a, node b) {
  return node(a.no_4 + b.no_4, a.no_7 + b.no_7,
              max(a.no_47 + b.no_7, a.no_4 + b.no_47, a.no_4 + b.no_7),
              max(a.no_74 + b.no_4, a.no_7 + b.no_74, a.no_7 + b.no_4));
}
string hell;
void build(int root, int tree_left, int tree_right) {
  if (tree_left == tree_right) {
    if (hell[tree_left] == '4')
      tree[root] = node(1, 0, 1, 1);
    else
      tree[root] = node(0, 1, 1, 1);
  } else {
    int tree_mid = (tree_left + tree_right) / 2;
    build((root * 2), tree_left, tree_mid);
    build((root * 2 + 1), tree_mid + 1, tree_right);
    tree[root] = func(tree[(root * 2)], tree[(root * 2 + 1)]);
  }
}
void updateRange(int root, int tree_left, int tree_right, int up_left,
                 int up_right, int val) {
  if (tree[root].prop) {
    swap(tree[root].no_47, tree[root].no_74);
    swap(tree[root].no_4, tree[root].no_7);
    if (tree_left != tree_right) {
      tree[(root * 2)].prop ^= 1;
      tree[(root * 2 + 1)].prop ^= 1;
    }
    tree[root].prop = 0;
  }
  if (tree_left > up_right || tree_left > tree_right || tree_right < up_left)
    return;
  else if (up_left <= tree_left && tree_right <= up_right) {
    swap(tree[root].no_47, tree[root].no_74);
    swap(tree[root].no_4, tree[root].no_7);
    int i = root;
    if (tree_left != tree_right) {
      tree[(root * 2)].prop ^= 1;
      tree[(root * 2 + 1)].prop ^= 1;
    }
  } else {
    int tree_mid = (tree_left + tree_right) / 2;
    updateRange((root * 2), tree_left, tree_mid, up_left, up_right, val);
    updateRange((root * 2 + 1), tree_mid + 1, tree_right, up_left, up_right,
                val);
    tree[root] = func(tree[((root)*2)], tree[(root * 2 + 1)]);
  }
  return;
}
void print_segment_tree(int lim = 40) {
  printf("\nSegment tree:\n");
  for (int i = 1, j = 1; i < lim; ++i) {
    if (i == (1 << j)) {
      ++j;
      printf("\n");
    }
    printf("(%d,%d,%d,%d,%d) ", tree[i].no_4, tree[i].no_7, tree[i].no_47,
           tree[i].no_74, tree[i].prop);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m, p, q;
  cin >> n >> m;
  string x;
  cin >> hell;
  build(1, 0, n - 1);
  while (m--) {
    cin >> x;
    if (x[0] == 'c') {
      cout << tree[1].no_47 << endl;
    } else {
      cin >> p >> q;
      updateRange(1, 0, n - 1, --p, --q, p);
    }
  }
  return 0;
}
