#include <bits/stdc++.h>
using namespace std;
int n, q;
int arr[1000010], lazy[1000010 << 2];
string str;
struct data {
  int n4, n7, n47, n74;
  data() { n4 = n7 = n47 = n74 = 0; }
} tree[1000010 << 2];
void build(int node, int l, int r) {
  if (l == r) {
    tree[node].n4 = (arr[l] == 4);
    tree[node].n7 = (arr[l] == 7);
    tree[node].n47 = 1;
    tree[node].n74 = 1;
    return;
  }
  int mid = (l + r) >> 1;
  build(node << 1, l, mid);
  build(node << 1 | 1, mid + 1, r);
  tree[node].n4 = tree[node << 1].n4 + tree[node << 1 | 1].n4;
  tree[node].n7 = tree[node << 1].n7 + tree[node << 1 | 1].n7;
  tree[node].n47 = max(max(tree[node << 1].n47 + tree[node << 1 | 1].n7,
                           tree[node << 1].n4 + tree[node << 1 | 1].n47),
                       tree[node << 1].n4 + tree[node << 1 | 1].n7);
  tree[node].n74 = max(max(tree[node << 1].n7 + tree[node << 1 | 1].n74,
                           tree[node << 1].n74 + tree[node << 1 | 1].n4),
                       tree[node << 1].n7 + tree[node << 1 | 1].n4);
}
void propagate(int node) {
  if (lazy[node]) {
    lazy[node << 1] ^= 1, lazy[node << 1 | 1] ^= 1;
    swap(tree[node << 1].n4, tree[node << 1].n7);
    swap(tree[node << 1 | 1].n4, tree[node << 1 | 1].n7);
    swap(tree[node << 1].n47, tree[node << 1].n74);
    swap(tree[node << 1 | 1].n47, tree[node << 1 | 1].n74);
  }
  lazy[node] = 0;
}
void update(int node, int l, int r, int i, int j) {
  if (r < i || l > j) return;
  if (i <= l && r <= j) {
    lazy[node] ^= 1;
    swap(tree[node].n4, tree[node].n7);
    swap(tree[node].n47, tree[node].n74);
    return;
  }
  int mid = (l + r) >> 1;
  propagate(node);
  update(node << 1, l, mid, i, j);
  update(node << 1 | 1, mid + 1, r, i, j);
  tree[node].n4 = tree[node << 1].n4 + tree[node << 1 | 1].n4;
  tree[node].n7 = tree[node << 1].n7 + tree[node << 1 | 1].n7;
  tree[node].n47 = max(max(tree[node << 1].n47 + tree[node << 1 | 1].n7,
                           tree[node << 1].n4 + tree[node << 1 | 1].n47),
                       tree[node << 1].n4 + tree[node << 1 | 1].n7);
  tree[node].n74 = max(max(tree[node << 1].n7 + tree[node << 1 | 1].n74,
                           tree[node << 1].n74 + tree[node << 1 | 1].n4),
                       tree[node << 1].n7 + tree[node << 1 | 1].n4);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> q;
  for (int i = 0; i < n; ++i) {
    char c;
    cin >> c;
    arr[i + 1] = c - '0';
  }
  build(1, 1, n);
  while (q--) {
    cin >> str;
    if (str == "count") {
      cout << tree[1].n47 << '\n';
    } else {
      int l, r;
      cin >> l >> r;
      update(1, 1, n, l, r);
    }
  }
}
