#include <bits/stdc++.h>
using namespace std;
const double eps = 0.000000000000001;
string convertstring(long long n) {
  stringstream ss;
  ss << n;
  return ss.str();
}
char s[1000005], misc[10];
struct box {
  int cnt4, cnt7, inc, dec;
} tree[4 * 1000005];
bool lazy[4 * 1000005];
void build(int node, int st, int en) {
  if (st == en) {
    tree[node] = (box){s[st] == '4', s[st] == '7', 1, 1};
    return;
  }
  int left = node << 1, right = (node << 1) + 1;
  build(left, st, st + en >> 1);
  build(right, (st + en >> 1) + 1, en);
  tree[node].cnt4 = tree[left].cnt4 + tree[right].cnt4;
  tree[node].cnt7 = tree[left].cnt7 + tree[right].cnt7;
  tree[node].inc =
      max(tree[left].cnt4 + tree[right].inc, tree[left].inc + tree[right].cnt7);
  tree[node].dec =
      max(tree[left].cnt7 + tree[right].dec, tree[left].dec + tree[right].cnt4);
}
void update(int node, int st, int en, int qst, int qen) {
  int left = node << 1, right = (node << 1) + 1;
  if (lazy[node]) {
    swap(tree[node].cnt4, tree[node].cnt7);
    swap(tree[node].inc, tree[node].dec);
    if (st != en) {
      lazy[left] ^= 1;
      lazy[right] ^= 1;
    }
    lazy[node] = 0;
  }
  if (st > qen || st > en || en < qst) return;
  if (st >= qst && en <= qen) {
    swap(tree[node].cnt4, tree[node].cnt7);
    swap(tree[node].inc, tree[node].dec);
    if (st != en) {
      lazy[left] ^= 1;
      lazy[right] ^= 1;
    }
    return;
  }
  int mid = st + en >> 1;
  update(left, st, mid, qst, qen);
  update(right, mid + 1, en, qst, qen);
  tree[node].cnt4 = tree[left].cnt4 + tree[right].cnt4;
  tree[node].cnt7 = tree[left].cnt7 + tree[right].cnt7;
  tree[node].inc =
      max(tree[left].cnt4 + tree[right].inc, tree[left].inc + tree[right].cnt7);
  tree[node].dec =
      max(tree[left].cnt7 + tree[right].dec, tree[left].dec + tree[right].cnt4);
}
int main() {
  int n, q, i, j;
  scanf("%d%d", &n, &q);
  ;
  scanf("%s", s + 1);
  build(1, 1, n);
  while (q--) {
    scanf("%s", misc);
    if (misc[0] == 's') {
      int l, r;
      scanf("%d%d", &l, &r);
      ;
      update(1, 1, n, l, r);
    } else {
      int ans = tree[1].inc;
      printf("%d\n", ans);
    }
  }
  return 0;
}
