#include <bits/stdc++.h>
using namespace std;
struct node {
  int _4s, _7s, _47, _74;
  void init(int _4, int _7) {
    _4s = _4;
    _7s = _7;
    _47 = _74 = _4 + _7;
  }
  void init(node l, node r) {
    this->_4s = l._4s + r._4s;
    this->_7s = l._7s + r._7s;
    this->_47 = max(l._47 + r._7s, l._4s + r._47);
    this->_74 = max(l._7s + r._74, l._74 + r._4s);
  }
  void swap() {
    std::swap(_4s, _7s);
    std::swap(_47, _74);
  }
} segtree[4 * 1000000 + 1];
string X;
vector<bool> lazy(4 * 1000000 + 1, false);
void build(int beg, int end, int in) {
  if (end < beg) return;
  if (beg == end) {
    segtree[in].init(X[beg] == '4', X[beg] == '7');
    return;
  }
  int mid = (beg + end) >> 1;
  build(beg, mid, in << 1);
  build(mid + 1, end, in << 1 | 1);
  segtree[in].init(segtree[in << 1], segtree[in << 1 | 1]);
}
void update(int beg, int end, int l, int r, int in) {
  if (lazy[in]) {
    lazy[in] = false;
    segtree[in].swap();
    if (beg != end) {
      lazy[in << 1] = lazy[in << 1] ^ true;
      lazy[in << 1 | 1] = lazy[in << 1 | 1] ^ true;
    }
  }
  if (beg > end || r < beg || l > end) return;
  if (l <= beg && end <= r) {
    segtree[in].swap();
    if (beg != end) {
      lazy[in << 1] = lazy[in << 1] ^ true;
      lazy[in << 1 | 1] = lazy[in << 1 | 1] ^ true;
    }
    return;
  }
  int mid = (beg + end) >> 1;
  update(beg, mid, l, r, in << 1);
  update(mid + 1, end, l, r, in << 1 | 1);
  segtree[in].init(segtree[in << 1], segtree[in << 1 | 1]);
}
int main() {
  int n, m, a, b;
  cin >> n >> m;
  cin >> X;
  build(0, n - 1, 1);
  string s;
  for (int i = 0; i < m; i++) {
    cin >> s;
    if (s == "count")
      printf("%d\n", segtree[1]._47);
    else {
      scanf("%d%d", &a, &b);
      update(0, n - 1, a - 1, b - 1, 1);
    }
  }
  return 0;
}
