#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
class SegTree {
 public:
  int tag[2097152];
  int ans[2097152], rev[2097152];
  int clr[2097152], bit[2097152];
  void init(int n) {
    for (int i = 0; i < n; i++) {
      int t = 1, x = 0, y = n;
      while (x + 1 != y) {
        int m = (x + y) / 2;
        if (i < m)
          t = t * 2, y = m;
        else
          t = t * 2 + 1, x = m;
      }
      tag[t] = bit[t] = 0;
      ans[t] = rev[t] = clr[t] = 1;
      while (t /= 2) calcup(t * 2, t * 2 + 1, t);
    }
  }
  void passdn(int p, int q, int t) {
    if (!tag[t]) return;
    tag[p] ^= 1, tag[q] ^= 1;
    swap(clr[p], bit[p]);
    swap(clr[q], bit[q]);
    swap(ans[p], rev[p]);
    swap(ans[q], rev[q]);
    tag[t] = 0;
  }
  void calcup(int p, int q, int t) {
    clr[t] = clr[p] + clr[q];
    bit[t] = bit[p] + bit[q];
    ans[t] = max(ans[p] + bit[q], clr[p] + ans[q]);
    rev[t] = max(rev[p] + clr[q], bit[p] + rev[q]);
  }
  void modify(int L, int R, int x, int y, int t) {
    if (L <= x && y <= R) {
      tag[t] ^= 1;
      swap(clr[t], bit[t]);
      swap(ans[t], rev[t]);
      return;
    }
    int m = (x + y) / 2, p = t * 2, q = p + 1;
    passdn(p, q, t);
    if (L < m) modify(L, R, x, m, p);
    if (m < R) modify(L, R, m, y, q);
    calcup(p, q, t);
  }
  pair<int, pair<int, int>> getans(int L, int R, int x, int y, int t) {
    if (L <= x && y <= R) return {ans[t], {clr[t], bit[t]}};
    int m = (x + y) / 2, p = t * 2, q = p + 1;
    passdn(p, q, t);
    pair<int, pair<int, int>> lhs, rhs;
    if (L < m) lhs = getans(L, R, x, m, p);
    if (m < R) rhs = getans(L, R, m, y, q);
    calcup(p, q, t);
    return {max(lhs.first + rhs.second.second, rhs.first + lhs.second.first),
            {lhs.second.first + rhs.second.first,
             lhs.second.second + rhs.second.second}};
  }
} st;
char s[1000005];
int main() {
  int n, m, x, y;
  scanf("%d%d%s", &n, &m, s);
  st.init(n);
  for (int i = 0; i < n; i++)
    if (s[i] == '7') st.modify(i, i + 1, 0, n, 1);
  for (int i = 0; i < m; i++) {
    scanf("%s", s);
    if (*s == 'c') {
      printf("%d\n", st.getans(0, n, 0, n, 1).first);
    } else {
      scanf("%d%d", &x, &y);
      st.modify(x - 1, y, 0, n, 1);
    }
  }
}
