#include <bits/stdc++.h>
using namespace std;
int n, m, a[1000050];
char s[1000050];
struct node {
  int cnt[2], sum[2], rev;
  void init() { cnt[0] = cnt[1] = sum[0] = sum[1] = rev = 0; }
} t[1000050 << 2];
node merge(node x, node y) {
  node ret;
  ret.init();
  ret.cnt[0] = x.cnt[0] + y.cnt[0];
  ret.cnt[1] = x.cnt[1] + y.cnt[1];
  ret.sum[0] =
      max(x.cnt[0] + y.cnt[1], max(x.sum[0] + y.cnt[1], x.cnt[0] + y.sum[0]));
  ret.sum[1] =
      max(x.cnt[1] + y.cnt[0], max(x.sum[1] + y.cnt[0], x.cnt[1] + y.sum[1]));
  return ret;
}
void Rev(int u) {
  t[u].rev ^= 1, swap(t[u].cnt[0], t[u].cnt[1]), swap(t[u].sum[0], t[u].sum[1]);
}
void push(int u) {
  if (!t[u].rev) return;
  Rev(u << 1), Rev(u << 1 | 1), t[u].rev = 0;
}
void print(node x) {
  cout << x.cnt[0] << ' ' << x.cnt[1] << ' ' << x.sum[0] << ' ' << x.sum[1]
       << endl;
}
void build(int u, int l, int r) {
  if (l == r) {
    t[u].cnt[a[l]] = 1, t[u].sum[0] = t[u].sum[1] = 1;
    return;
  }
  build(u << 1, l, ((l + r) >> 1)), build(u << 1 | 1, ((l + r) >> 1) + 1, r);
  t[u] = merge(t[u << 1], t[u << 1 | 1]);
}
void change(int u, int l, int r, int tl, int tr) {
  if (tl <= l && r <= tr) {
    Rev(u);
    return;
  }
  push(u);
  if (tl <= ((l + r) >> 1)) change(u << 1, l, ((l + r) >> 1), tl, tr);
  if (((l + r) >> 1) < tr) change(u << 1 | 1, ((l + r) >> 1) + 1, r, tl, tr);
  t[u] = merge(t[u << 1], t[u << 1 | 1]);
}
int main() {
  scanf("%d%d", &n, &m);
  scanf("%s", s + 1);
  for (register int i = 1; i <= n; ++i)
    if (s[i] == '7') a[i] = 1;
  build(1, 1, n);
  int l, r;
  while (m--) {
    scanf("%s", s);
    if (s[0] == 'c')
      cout << t[1].sum[0] << endl;
    else {
      scanf("%d%d", &l, &r);
      change(1, 1, n, l, r);
    }
  }
  return 0;
}
