#include <bits/stdc++.h>
using ll = long long;
using namespace std;
struct Ruru {
  int cnt4, cnt7, cnt47, cnt74;
  const Ruru operator+(const Ruru &other) const {
    return {cnt4 + other.cnt4, cnt7 + other.cnt7,
            max({cnt47 + other.cnt7, cnt4 + other.cnt47, cnt4 + other.cnt7}),
            max({cnt74 + other.cnt4, cnt7 + other.cnt74, cnt7 + other.cnt4})};
  }
};
vector<Ruru> tree(4 * 1000001);
vector<int> diff(4 * 1000001);
void Push(int v, int vl, int vr) {
  if (diff[v] != 0) {
    tree[v] = {tree[v].cnt7, tree[v].cnt4, tree[v].cnt74, tree[v].cnt47};
    if (vl != vr) {
      diff[2 * v + 1] = (diff[2 * v + 1] + 1) % 2;
      diff[2 * v + 2] = (diff[2 * v + 2] + 1) % 2;
    }
  }
  diff[v] = 0;
}
void Grow(int v, int vl, int vr, string &data) {
  if (vl == vr) {
    if (data[vl] == '4') {
      tree[v] = {1, 0, 1, 1};
    } else {
      tree[v] = {0, 1, 1, 1};
    }
    return;
  }
  int vm = (vl + vr) / 2;
  Grow(2 * v + 1, vl, vm, data);
  Grow(2 * v + 2, vm + 1, vr, data);
  tree[v] = tree[2 * v + 1] + tree[2 * v + 2];
}
void Switch(int v, int vl, int vr, int l, int r) {
  Push(v, vl, vr);
  if (vl > r || l > vr) {
    return;
  }
  if (vl >= l && vr <= r) {
    diff[v] = (diff[v] + 1) % 2;
    Push(v, vl, vr);
    return;
  }
  int vm = (vl + vr) / 2;
  Switch(2 * v + 1, vl, vm, l, r);
  Switch(2 * v + 2, vm + 1, vr, l, r);
  tree[v] = tree[2 * v + 1] + tree[2 * v + 2];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, q;
  cin >> n >> q;
  string str1;
  cin >> str1;
  Grow(0, 0, str1.size() - 1, str1);
  for (int i = 0; i < q; i++) {
    string s;
    cin >> s;
    if (s == "count") {
      cout << tree[0].cnt47 << endl;
    } else {
      int a, b;
      cin >> a >> b;
      Switch(0, 0, str1.size() - 1, a - 1, b - 1);
    }
  }
  return 0;
}
