#include <bits/stdc++.h>
using namespace std;
struct node {
  long long int count_4;
  long long int count_7;
  long long int inc;
  long long int dec;
  node() {
    count_4 = 0;
    count_7 = 0;
    inc = 0;
    dec = 0;
  }
} tree[1 << 21];
long long int arr[1000007], lazy[1 << 21];
void build(long long int node, long long int a, long long int b) {
  if (a == b) {
    if (arr[a] == 4) {
      tree[node].count_4 = 1;
      tree[node].count_7 = 0;
    } else {
      tree[node].count_4 = 0;
      tree[node].count_7 = 1;
    }
    tree[node].inc = 1;
    tree[node].dec = 1;
    return;
  }
  long long int mid = (a + b) / 2;
  build(2 * node, a, mid);
  build(2 * node + 1, mid + 1, b);
  tree[node].count_4 = tree[2 * node].count_4 + tree[2 * node + 1].count_4;
  tree[node].count_7 = tree[2 * node].count_7 + tree[2 * node + 1].count_7;
  tree[node].inc = tree[2 * node].inc + tree[2 * node + 1].count_7;
  tree[node].inc =
      max(tree[node].inc, tree[2 * node].count_4 + tree[2 * node + 1].inc);
  tree[node].inc =
      max(tree[node].inc, tree[2 * node].count_4 + tree[2 * node + 1].count_7);
  tree[node].inc =
      max(tree[node].inc, tree[2 * node].count_4 + tree[2 * node + 1].count_4);
  tree[node].inc =
      max(tree[node].inc, tree[2 * node].count_7 + tree[2 * node + 1].count_7);
  tree[node].dec = tree[2 * node].count_7 + tree[2 * node + 1].dec;
  tree[node].dec =
      max(tree[node].dec, tree[2 * node].dec + tree[2 * node + 1].count_4);
  tree[node].dec =
      max(tree[node].dec, tree[2 * node].count_7 + tree[2 * node + 1].count_4);
  tree[node].dec =
      max(tree[node].dec, tree[2 * node].count_4 + tree[2 * node + 1].count_4);
  tree[node].dec =
      max(tree[node].dec, tree[2 * node].count_7 + tree[2 * node + 1].count_7);
}
void update(long long int node, long long int a, long long int b,
            long long int l, long long int r) {
  if (lazy[node]) {
    swap(tree[node].count_4, tree[node].count_7);
    swap(tree[node].inc, tree[node].dec);
    if (a != b) {
      lazy[2 * node] ^= 1;
      lazy[2 * node + 1] ^= 1;
    }
    lazy[node] = 0;
  }
  if (a > b || a > r || b < l) return;
  if (a >= l && b <= r) {
    swap(tree[node].count_4, tree[node].count_7);
    swap(tree[node].inc, tree[node].dec);
    if (a != b) {
      lazy[2 * node] ^= 1;
      lazy[2 * node + 1] ^= 1;
    }
    return;
  }
  long long int mid = (a + b) / 2;
  update(2 * node, a, mid, l, r);
  update(2 * node + 1, mid + 1, b, l, r);
  tree[node].count_4 = tree[2 * node].count_4 + tree[2 * node + 1].count_4;
  tree[node].count_7 = tree[2 * node].count_7 + tree[2 * node + 1].count_7;
  tree[node].inc = tree[2 * node].inc + tree[2 * node + 1].count_7;
  tree[node].inc =
      max(tree[node].inc, tree[2 * node].count_4 + tree[2 * node + 1].inc);
  tree[node].inc =
      max(tree[node].inc, tree[2 * node].count_4 + tree[2 * node + 1].count_7);
  tree[node].inc =
      max(tree[node].inc, tree[2 * node].count_4 + tree[2 * node + 1].count_4);
  tree[node].inc =
      max(tree[node].inc, tree[2 * node].count_7 + tree[2 * node + 1].count_7);
  tree[node].dec = tree[2 * node].count_7 + tree[2 * node + 1].dec;
  tree[node].dec =
      max(tree[node].dec, tree[2 * node].dec + tree[2 * node + 1].count_4);
  tree[node].dec =
      max(tree[node].dec, tree[2 * node].count_7 + tree[2 * node + 1].count_4);
  tree[node].dec =
      max(tree[node].dec, tree[2 * node].count_4 + tree[2 * node + 1].count_4);
  tree[node].dec =
      max(tree[node].dec, tree[2 * node].count_7 + tree[2 * node + 1].count_7);
}
int detect(string s) {
  if (s[0] == 'c') return 2;
  return 1;
}
int main() {
  ios::sync_with_stdio(false);
  ;
  cin.tie(0);
  long long int i, j, n, q, l, r, x, y, type;
  string s;
  cin >> n >> q;
  cin >> s;
  s = " " + s;
  for (i = 1; i <= n; i++) {
    if (s[i] == '4')
      arr[i] = 4;
    else
      arr[i] = 7;
  }
  build(1, 1, n);
  while (q--) {
    cin >> s;
    type = detect(s);
    if (type == 1) {
      cin >> l >> r;
      update(1, 1, n, l, r);
    } else
      cout << tree[1].inc << endl;
  }
  return 0;
}
