#include <bits/stdc++.h>
using namespace std;
long long M = (1e9) + 7;
long long t[4][3000005], lazy[3000005];
string x;
void build(long long id, long long n, long long s, long long e) {
  if (s > e)
    return;
  else if (s == e) {
    if (id == 0) {
      t[id][n] = (x[s] == '4') ? 1 : 0;
    } else if (id == 1) {
      t[id][n] = (x[s] == '7') ? 1 : 0;
    } else if (id == 2) {
      t[id][n] = 1;
    } else {
      t[id][n] = 1;
    }
  } else {
    long long m = (s + e) / 2;
    build(id, n * 2 + 1, s, m);
    build(id, n * 2 + 2, m + 1, e);
    if (id == 0) {
      t[id][n] = t[id][2 * n + 1] + t[id][2 * n + 2];
    } else if (id == 1) {
      t[id][n] = t[id][2 * n + 1] + t[id][2 * n + 2];
    } else if (id == 2) {
      t[id][n] = max(t[id][2 * n + 1] + t[1][2 * n + 2],
                     max(t[0][2 * n + 1] + t[id][2 * n + 2],
                         t[0][2 * n + 1] + t[1][2 * n + 2]));
      t[id][n] = max(t[id][n], t[0][n]);
      t[id][n] = max(t[id][n], t[1][n]);
    } else {
      t[id][n] = max(t[id][2 * n + 1] + t[0][2 * n + 2],
                     max(t[1][2 * n + 1] + t[id][2 * n + 2],
                         t[1][2 * n + 1] + t[0][2 * n + 2]));
      t[id][n] = max(t[id][n], t[0][n]);
      t[id][n] = max(t[id][n], t[1][n]);
    }
  }
}
void upd(long long n, long long s, long long e, long long l, long long r) {
  if (lazy[n]) {
    swap(t[1][n], t[0][n]);
    swap(t[2][n], t[3][n]);
    if (s != e)
      lazy[2 * n + 1] = 1 - lazy[2 * n + 1],
                   lazy[2 * n + 2] = 1 - lazy[2 * n + 2];
    lazy[n] = 0;
  }
  if (s > e || s > r || e < l) return;
  if (l <= s && e <= r) {
    swap(t[1][n], t[0][n]);
    swap(t[2][n], t[3][n]);
    if (s != e)
      lazy[2 * n + 1] = 1 - lazy[2 * n + 1],
                   lazy[2 * n + 2] = 1 - lazy[2 * n + 2];
    return;
  }
  long long m = (s + e) / 2;
  upd(n * 2 + 1, s, m, l, r);
  upd(n * 2 + 2, m + 1, e, l, r);
  for (long long id = 0; id < 4; id++) {
    if (id == 0) {
      t[id][n] = t[id][2 * n + 1] + t[id][2 * n + 2];
    } else if (id == 1) {
      t[id][n] = t[id][2 * n + 1] + t[id][2 * n + 2];
    } else if (id == 2) {
      t[id][n] = max(t[id][2 * n + 1] + t[1][2 * n + 2],
                     max(t[0][2 * n + 1] + t[id][2 * n + 2],
                         t[0][2 * n + 1] + t[1][2 * n + 2]));
      t[id][n] = max(t[id][n], t[0][n]);
      t[id][n] = max(t[id][n], t[1][n]);
    } else {
      t[id][n] = max(t[id][2 * n + 1] + t[0][2 * n + 2],
                     max(t[1][2 * n + 1] + t[id][2 * n + 2],
                         t[1][2 * n + 1] + t[0][2 * n + 2]));
      t[id][n] = max(t[id][n], t[0][n]);
      t[id][n] = max(t[id][n], t[1][n]);
    }
  }
  return;
}
long long qur(long long id, long long n, long long s, long long e, long long l,
              long long r) {
  if (lazy[n]) {
    swap(t[1][n], t[0][n]);
    swap(t[2][n], t[3][n]);
    if (s != e)
      lazy[2 * n + 1] = 1 - lazy[2 * n + 1],
                   lazy[2 * n + 2] = 1 - lazy[2 * n + 2];
    lazy[n] = 0;
  }
  if (s > e || s > r || e < l) return 0;
  if (l <= s && e <= r) return t[id][n];
  long long m = (s + e) / 2;
  return qur(id, n * 2 + 1, s, m, l, r) + qur(id, n * 2 + 2, m + 1, e, l, r);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long tc = 1;
  for (long long ti = 1; ti <= tc; ti++) {
    long long n, m;
    cin >> n >> m;
    cin >> x;
    for (long long i = 0; i < 4; i++) build(i, 0, 0, n - 1);
    for (long long i = 0; i < m; i++) {
      string q;
      cin >> q;
      if (q[0] == 'c') {
        cout << qur(2, 0, 0, n - 1, 0, n - 1) << endl;
      } else {
        long long l, r;
        cin >> l >> r;
        l--, r--;
        upd(0, 0, n - 1, l, r);
      }
    }
  }
  return 0;
}
