#include <bits/stdc++.h>
using namespace std;
long long n, m;
string s;
struct node {
  long long cnt4, cnt7, inc, dec;
};
node tree[4000005];
long long lazy[4000005];
void build(long long si, long long second, long long se) {
  if (second == se) {
    tree[si].cnt4 = 0;
    tree[si].cnt7 = 0;
    tree[si].inc = 0;
    tree[si].dec = 0;
    if (s[second] == '4')
      tree[si].cnt4 = 1;
    else
      tree[si].cnt7 = 1;
    return;
  }
  long long mid = (second + se) / 2;
  build(si * 2 + 1, second, mid);
  build(si * 2 + 2, mid + 1, se);
  tree[si].cnt4 = tree[si * 2 + 1].cnt4 + tree[si * 2 + 2].cnt4;
  tree[si].cnt7 = tree[si * 2 + 1].cnt7 + tree[si * 2 + 2].cnt7;
  tree[si].inc = max(
      tree[si * 2 + 1].inc,
      max(tree[si * 2 + 2].inc, tree[si * 2 + 1].cnt4 + tree[si * 2 + 2].cnt7));
  tree[si].inc =
      max(tree[si].inc, max(tree[si * 2 + 1].inc + tree[si * 2 + 2].cnt7,
                            tree[si * 2 + 1].cnt4 + tree[si * 2 + 2].inc));
  tree[si].dec = max(
      tree[si * 2 + 1].dec,
      max(tree[si * 2 + 2].dec, tree[si * 2 + 1].cnt7 + tree[si * 2 + 2].cnt4));
  tree[si].dec =
      max(tree[si].dec, max(tree[si * 2 + 1].dec + tree[si * 2 + 2].cnt4,
                            tree[si * 2 + 1].cnt7 + tree[si * 2 + 2].dec));
}
void update(long long si, long long second, long long se, long long qs,
            long long qe) {
  if (lazy[si]) {
    swap(tree[si].cnt4, tree[si].cnt7);
    swap(tree[si].inc, tree[si].dec);
    lazy[si] = 0;
    if (second != se) {
      lazy[si * 2 + 1] = 1 - lazy[si * 2 + 1];
      lazy[si * 2 + 2] = 1 - lazy[si * 2 + 2];
    }
  }
  if (qe < second || qs > se) return;
  if (second >= qs && se <= qe) {
    swap(tree[si].cnt4, tree[si].cnt7);
    swap(tree[si].inc, tree[si].dec);
    if (second != se) {
      lazy[si * 2 + 1] = 1 - lazy[si * 2 + 1];
      lazy[si * 2 + 2] = 1 - lazy[si * 2 + 2];
    }
    return;
  }
  long long mid = (second + se) / 2;
  update(si * 2 + 1, second, mid, qs, qe);
  update(si * 2 + 2, mid + 1, se, qs, qe);
  tree[si].cnt4 = tree[si * 2 + 1].cnt4 + tree[si * 2 + 2].cnt4;
  tree[si].cnt7 = tree[si * 2 + 1].cnt7 + tree[si * 2 + 2].cnt7;
  tree[si].inc = max(
      tree[si * 2 + 1].inc,
      max(tree[si * 2 + 2].inc, tree[si * 2 + 1].cnt4 + tree[si * 2 + 2].cnt7));
  tree[si].inc =
      max(tree[si].inc, max(tree[si * 2 + 1].inc + tree[si * 2 + 2].cnt7,
                            tree[si * 2 + 1].cnt4 + tree[si * 2 + 2].inc));
  tree[si].dec = max(
      tree[si * 2 + 1].dec,
      max(tree[si * 2 + 2].dec, tree[si * 2 + 1].cnt7 + tree[si * 2 + 2].cnt4));
  tree[si].dec =
      max(tree[si].dec, max(tree[si * 2 + 1].dec + tree[si * 2 + 2].cnt4,
                            tree[si * 2 + 1].cnt7 + tree[si * 2 + 2].dec));
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  cin >> s;
  build(0, 0, n - 1);
  while (m--) {
    string t;
    cin >> t;
    if (t == "count") {
      cout << max(tree[0].inc, max(tree[0].cnt4, tree[0].cnt7)) << "\n";
    } else {
      long long l, r;
      cin >> l >> r;
      l--;
      r--;
      update(0, 0, n - 1, l, r);
    }
  }
  return 0;
}
