#include <bits/stdc++.h>
using namespace std;
struct Node {
  int x[4];
  int len;
};
Node tree[4 * 1000005], zero;
bool lazy[4 * 1000005];
char s[1000005];
Node merge(Node a, Node b) {
  Node temp;
  temp.x[0] = a.x[0] + b.x[0];
  temp.x[3] = a.x[3] + b.x[3];
  temp.x[1] =
      max(a.x[1], max(b.x[1], max(a.x[0] && b.x[3] ? a.x[0] + b.x[3] : 0,
                                  a.x[1] && b.x[3] ? a.x[1] + b.x[3] : 0)));
  temp.x[2] =
      max(a.x[2], max(b.x[2], max(a.x[2] && b.x[0] ? a.x[2] + b.x[0] : 0,
                                  a.x[3] && b.x[0] ? a.x[3] + b.x[0] : 0)));
  temp.x[1] = max(temp.x[1], a.x[0] && b.x[1] ? a.x[0] + b.x[1] : 0);
  temp.x[2] = max(temp.x[2], a.x[3] && b.x[2] ? a.x[3] + b.x[2] : 0);
  int len = 0;
  for (int i = 0; i < 4; i++)
    if (i != 2) len = max(len, temp.x[i]);
  temp.len = len;
  return temp;
}
void build(int node, int a, int b) {
  if (a > b) return;
  if (a == b) {
    tree[node].len = 1;
    if (s[a] == '4') {
      tree[node].x[0] = 1;
    } else {
      tree[node].x[3] = 1;
    }
    return;
  }
  int left, right;
  left = 2 * node + 1, right = 2 * node + 2;
  build(left, a, (a + b) / 2);
  build(right, (a + b) / 2 + 1, b);
  tree[node] = merge(tree[left], tree[right]);
}
void lazy_update(int node, int a, int b) {
  int left, right, len = 0;
  left = 2 * node + 1, right = 2 * node + 2;
  swap(tree[node].x[0], tree[node].x[3]);
  swap(tree[node].x[1], tree[node].x[2]);
  if (a != b) {
    lazy[left] ^= 1;
    lazy[right] ^= 1;
  }
  for (int i = 0; i < 4; i++)
    if (i != 2) len = max(len, tree[node].len);
  tree[node].len = len;
  lazy[node] = 0;
}
void update(int node, int a, int b, int i, int j) {
  if (lazy[node]) {
    lazy_update(node, a, b);
  }
  int left, right;
  left = 2 * node + 1, right = 2 * node + 2;
  if (a > b || a > j || b < i) return;
  if (a >= i && b <= j) {
    int len = 0;
    swap(tree[node].x[0], tree[node].x[3]);
    swap(tree[node].x[1], tree[node].x[2]);
    for (int i = 0; i < 4; i++)
      if (i != 2) len = max(len, tree[node].len);
    tree[node].len = len;
    if (a != b) {
      lazy[left] ^= 1;
      lazy[right] ^= 1;
    }
    return;
  }
  update(left, a, (a + b) / 2, i, j);
  update(right, (a + b) / 2 + 1, b, i, j);
  tree[node] = merge(tree[left], tree[right]);
}
Node query(int node, int a, int b, int i, int j) {
  if (lazy[node]) {
    lazy_update(node, a, b);
  }
  if (a > b || a > j || b < i) return zero;
  if (a >= i && b <= j) return tree[node];
  int left, right;
  left = 2 * node + 1, right = 2 * node + 2;
  Node c, d;
  c = query(left, a, (a + b) / 2, i, j);
  d = query(right, (a + b) / 2 + 1, b, i, j);
  return merge(c, d);
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  scanf("%s", s);
  build(0, 0, n - 1);
  for (int i = 0; i < m; i++) {
    char type[10];
    scanf("%s", s);
    if (s[0] == 'c') {
      int ans = 0;
      Node temp = query(0, 0, n - 1, 0, n - 1);
      for (int i = 0; i < 4; i++) {
        if (i != 2) ans = max(ans, temp.x[i]);
      }
      printf("%d\n", ans);
    } else {
      int l, r;
      scanf("%d %d", &l, &r);
      l--, r--;
      update(0, 0, n - 1, l, r);
    }
  }
  return 0;
}
