#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6 + 10;
int n;
int m;
vector<int> ans;
string s;
bool check[4 * maxn];
int lazy[4 * maxn];
int anti[4 * maxn];
int four[4 * maxn];
int seven[4 * maxn];
void input();
void ok_lazy(int id);
void build(int id, int l, int r);
void shift(int id);
void update(int id, int l, int r, int l1, int r1);
void get(int id, int l, int r, int l1, int r1);
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  input();
  return 0;
}
void input() {
  cin >> n >> m >> s;
  build(1, 0, s.size());
  for (int i = 0; i < m; i++) {
    string f;
    cin >> f;
    if (f == "count") {
      cout << lazy[1] << endl;
    } else {
      int k;
      int q;
      cin >> k >> q;
      k--;
      q--;
      update(1, 0, n, k, q + 1);
    }
  }
}
void ok_lazy(int id) {
  if (check[id] == 1) {
    check[(id << 1)] ^= 1;
    check[(id << 1) | 1] ^= 1;
    int u = lazy[id];
    int j = seven[id];
    seven[id] = four[id];
    lazy[id] = anti[id];
    four[id] = j;
    anti[id] = u;
    check[id] = 0;
    return;
  }
  return;
}
void shift(int id) {
  four[id] = four[id << 1] + four[(id << 1) | 1];
  seven[id] = seven[id << 1] + seven[(id << 1) | 1];
  anti[id] = max(seven[id << 1] + seven[(id << 1) | 1],
                 max(four[id << 1] + four[(id << 1) | 1],
                     max(anti[id << 1] + four[(id << 1) | 1],
                         seven[id << 1] + anti[(id << 1) | 1])));
  lazy[id] = max(four[id << 1] + four[(id << 1) | 1],
                 max(four[id << 1] + lazy[(id << 1) | 1],
                     max(seven[id << 1] + seven[(id << 1) | 1],
                         lazy[id << 1] + seven[(id << 1) | 1])));
}
void build(int id, int l, int r) {
  if (r - l == 1) {
    if (s[l] == '4') {
      four[id]++;
      anti[id]++;
      lazy[id]++;
    } else {
      seven[id]++;
      anti[id]++;
      lazy[id]++;
    }
    return;
  }
  int mid = (r + l) >> 1;
  build(id << 1, l, mid);
  build((id << 1) | 1, mid, r);
  shift(id);
}
void update(int id, int l, int r, int l1, int r1) {
  if (l1 <= l && r <= r1) {
    ok_lazy(id);
    check[id] = 1;
    ok_lazy(id);
    return;
  }
  if (l1 >= r || r1 <= l) {
    ok_lazy(id);
    return;
  }
  int mid = (r + l) >> 1;
  ok_lazy(id);
  update(id << 1, l, mid, l1, r1);
  update((id << 1) | 1, mid, r, l1, r1);
  ok_lazy(id);
  shift(id);
}
void get(int id, int l, int r, int l1, int r1) {
  if (l1 <= l && r <= r1) {
    ans.emplace_back(id);
    return;
  }
  if (l1 >= r || r1 <= l) {
    return;
  }
  int mid = (r + l) >> 1;
  get(id << 1, l, mid, l1, r1);
  get((id << 1) | 1, mid, r, l1, r1);
  shift(id);
}
