#include <bits/stdc++.h>
using namespace std;
template <typename _Tp>
bool maximize(_Tp &__a, const _Tp &__b) {
  if (__a < __b) {
    __a = __b;
    return true;
  }
  return false;
}
template <typename _Tp>
bool minimize(_Tp &__a, const _Tp &__b) {
  if (__a > __b) {
    __a = __b;
    return true;
  }
  return false;
}
const int siz = 1e6 + 2;
const int SIZ = 1e6 + 2;
const int mod = 1e9 + 7;
const int maxx = 2e9;
const long long MAXX = 1e18;
const string file = "1";
struct segment_tree {
  struct node {
    int cnt_0, cnt_1, cnt_01, cnt_10;
    bool lazy;
    node(int cnt_0, int cnt_1, int cnt_01, int cnt_10)
        : cnt_0(cnt_0),
          cnt_1(cnt_1),
          cnt_01(cnt_01),
          cnt_10(cnt_10),
          lazy(false) {}
    node(int val) {
      if (val == 0) {
        *this = node(1, 0, 1, 1);
      } else {
        *this = node(0, 1, 1, 1);
      }
    }
    node() { *this = node(0, 0, 0, 0); }
    node operator+(const node &oth) const {
      return node(cnt_0 + oth.cnt_0, cnt_1 + oth.cnt_1,
                  max(cnt_0 + oth.cnt_01, cnt_01 + oth.cnt_1),
                  max(cnt_1 + oth.cnt_10, cnt_10 + oth.cnt_0));
    }
    node &operator+=(const node &oth) { return *this = *this + oth; }
  };
  int s, e;
  vector<node> tree;
  segment_tree(int s = 0, int e = 0) : s(s), e(e) {
    assert(0 <= s && s <= e);
    tree.assign(4 * (e - s + 1), node());
  }
  void build(int nd, int st, int ed, int *ar) {
    if (st == ed) {
      tree[nd] = ar[st];
      return;
    }
    int md = (st + ed) / 2;
    build(2 * nd, st, md, ar);
    build(2 * nd + 1, md + 1, ed, ar);
    tree[nd] = tree[2 * nd] + tree[2 * nd + 1];
  }
  void propagate(int nd, int st, int ed) {
    if (tree[nd].lazy != node().lazy) {
      swap(tree[nd].cnt_0, tree[nd].cnt_1);
      swap(tree[nd].cnt_01, tree[nd].cnt_10);
      if (st != ed) {
        tree[2 * nd].lazy ^= true;
        tree[2 * nd + 1].lazy ^= true;
      }
      tree[nd].lazy = node().lazy;
    }
  }
  void update(int nd, int st, int ed, int lt, int rt) {
    propagate(nd, st, ed);
    if (rt < st || ed < lt) {
      return;
    }
    if (lt <= st && ed <= rt) {
      tree[nd].lazy = true;
      propagate(nd, st, ed);
      return;
    }
    int md = (st + ed) / 2;
    update(2 * nd, st, md, lt, rt);
    update(2 * nd + 1, md + 1, ed, lt, rt);
    tree[nd] = tree[2 * nd] + tree[2 * nd + 1];
  }
  node query(int nd, int st, int ed, int lt, int rt) {
    propagate(nd, st, ed);
    if (rt < st || ed < lt) {
      return node();
    }
    if (lt <= st && ed <= rt) {
      return tree[nd];
    }
    int md = (st + ed) / 2;
    return query(2 * nd, st, md, lt, rt) +
           query(2 * nd + 1, md + 1, ed, lt, rt);
  }
  void build(int *ar) { build(1, s, e, ar); }
  void update(int lt, int rt) {
    assert(s <= lt && lt <= rt && rt <= e);
    update(1, s, e, lt, rt);
  }
  node query(int lt, int rt) {
    assert(s <= lt && lt <= rt && rt <= e);
    return query(1, s, e, lt, rt);
  }
};
int a[siz];
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  s = ' ' + s;
  for (int i = (int)(1); i <= (int)(n); i++) {
    a[i] = (s[i] == '4') ? 0 : 1;
  }
  segment_tree tree(1, n);
  tree.build(a);
  while (q--) {
    string t;
    cin >> t;
    if (t.front() == 's') {
      int l, r;
      cin >> l >> r;
      tree.update(l, r);
    } else {
      cout << tree.query(1, n).cnt_01 << "\n";
    }
  }
  return 0;
}
