#include <bits/stdc++.h>
using namespace std;
struct Node {
  int c4, c7, c47, c74;
  bool flip;
  Node(bool four = true) {
    if (four) {
      c47 = c74 = c4 = 1;
      c7 = 0;
    } else {
      c47 = c74 = c7 = 1;
      c4 = 0;
    }
    flip = false;
  }
  Node(Node a, Node b) {
    c4 = a.c4 + b.c4;
    c7 = a.c7 + b.c7;
    c47 = max(a.c4 + b.c47, a.c47 + b.c7);
    c74 = max(a.c7 + b.c74, a.c74 + b.c4);
  }
  void boom() {
    swap(c4, c7);
    swap(c47, c74);
  }
} T[1111111 * 4];
string S;
int N, M;
int ql, qr;
void push(int x, int l, int r) {
  T[x].boom();
  if (l != r) {
    T[2 * x].flip = not T[2 * x].flip;
    T[2 * x + 1].flip = not T[2 * x + 1].flip;
  }
}
void build(int x, int l, int r) {
  if (l == r) return void(T[x] = Node(S[l] == '4'));
  int m = (l + r) / 2;
  build(2 * x, l, m);
  build(2 * x + 1, m + 1, r);
  T[x] = Node(T[2 * x], T[2 * x + 1]);
}
void update(int x, int l, int r) {
  if (T[x].flip) {
    push(x, l, r);
    T[x].flip = false;
  }
  if (qr < ql or qr < l or r < ql) return;
  if (ql <= l and r <= qr) {
    push(x, l, r);
    return;
  }
  int m = (l + r) / 2;
  update(2 * x, l, m);
  update(2 * x + 1, m + 1, r);
  T[x] = Node(T[2 * x], T[2 * x + 1]);
}
int main() {
  char cmd[10];
  cin >> N >> M >> S;
  build(1, 0, N - 1);
  while (M--) {
    scanf("%s", cmd);
    if (cmd[0] == 'c') {
      printf("%d\n", T[1].c47);
    } else {
      scanf("%d %d", &ql, &qr);
      ql--;
      qr--;
      update(1, 0, N - 1);
    }
  }
}
