#include <bits/stdc++.h>
using namespace std;
int m, n;
char a[1234567] = {"4"};
struct st {
  int sw;
  int v74, v47, v4, v7;
} tr[4000000];
void init(int nd, int l, int r) {
  if (r == l + 1) {
    tr[nd].sw = 0;
    tr[nd].v74 = tr[nd].v7 = (a[l] == '7');
    tr[nd].v47 = tr[nd].v4 = (a[l] == '4');
    return;
  }
  init(nd * 2, l, (l + r) / 2);
  init(nd * 2 + 1, (l + r) / 2, r);
  int z = 2 * nd, y = 2 * nd + 1;
  tr[nd].sw = 0;
  tr[nd].v47 = max(tr[z].v47 + tr[y].v7, tr[z].v4 + tr[y].v47);
  tr[nd].v4 = tr[z].v4 + tr[y].v4;
  tr[nd].v7 = tr[z].v7 + tr[y].v7;
  tr[nd].v74 = max(tr[z].v74 + tr[y].v4, tr[z].v7 + tr[y].v74);
}
void push(int nd, int l, int r) {
  if (tr[nd].sw) {
    tr[nd].sw = 0;
    swap(tr[nd].v4, tr[nd].v7);
    swap(tr[nd].v47, tr[nd].v74);
    if (r > l + 1) {
      tr[2 * nd].sw ^= 1;
      tr[2 * nd + 1].sw ^= 1;
    }
  }
}
void swit(int nd, int l, int r, int x, int y) {
  if (l + 1 == r) {
    swap(tr[nd].v4, tr[nd].v7);
    swap(tr[nd].v47, tr[nd].v74);
    return;
  }
  if (l == x && r == y) {
    tr[nd].sw ^= 1;
    return;
  }
  int mm = (l + r) / 2, zo = 2 * nd, yo = 2 * nd + 1;
  if (mm <= x)
    swit(yo, mm, r, x, y);
  else if (mm >= y)
    swit(zo, l, mm, x, y);
  else {
    swit(zo, l, mm, x, mm);
    swit(yo, mm, r, mm, y);
  }
  push(zo, l, mm);
  push(yo, mm, r);
  tr[nd].v47 = max(tr[zo].v47 + tr[yo].v7, tr[zo].v4 + tr[yo].v47);
  tr[nd].v4 = tr[zo].v4 + tr[yo].v4;
  tr[nd].v7 = tr[zo].v7 + tr[yo].v7;
  tr[nd].v74 = max(tr[zo].v74 + tr[yo].v4, tr[zo].v7 + tr[yo].v74);
}
int main(int argc, char *argv[]) {
  scanf("%d%d", &n, &m);
  scanf("%s", a);
  init(1, 0, n);
  for (int q = 0; q < m; q++) {
    char cmd[10];
    scanf("%s", cmd);
    if (cmd[0] == 'c') {
      push(1, 0, n);
      printf("%d\n", max(tr[1].v47, tr[1].v7));
    } else {
      int x, y;
      scanf("%d%d", &x, &y);
      x--;
      swit(1, 0, n, x, y);
    }
  }
  return EXIT_SUCCESS;
}
