#include <bits/stdc++.h>
using namespace std;
const int N = 1000003;
int seg[4 * N][4];
string s;
int lazy[4 * N];
void fill(int i) {
  int l = 2 * i;
  int r = l + 1;
  seg[i][0] = seg[l][0] + seg[r][0];
  seg[i][1] = seg[l][1] + seg[r][1];
  seg[i][2] = max(seg[l][2] + seg[r][1], seg[l][0] + seg[r][2]);
  seg[i][3] = max(seg[l][3] + seg[r][0], seg[l][1] + seg[r][3]);
}
void build(int i, int l, int r) {
  if (l == r) {
    if (s[l] == '4')
      seg[i][0] = 1;
    else
      seg[i][1] = 1;
    seg[i][2] = seg[i][3] = 1;
    return;
  }
  int mid = (l + r) / 2;
  build(2 * i, l, mid);
  build(2 * i + 1, mid + 1, r);
  fill(i);
}
void upd(int i, int l, int r, int x, int y) {
  if (lazy[i]) {
    swap(seg[i][0], seg[i][1]);
    swap(seg[i][2], seg[i][3]);
    if (l != r) lazy[2 * i] ^= 1, lazy[2 * i + 1] ^= 1;
    lazy[i] = 0;
  }
  if (l >= x && r <= y) {
    swap(seg[i][0], seg[i][1]);
    swap(seg[i][2], seg[i][3]);
    if (l != r) {
      lazy[2 * i] ^= 1;
      lazy[2 * i + 1] ^= 1;
    }
    return;
  }
  if (l > y || r < x) return;
  int mid = (l + r) / 2;
  upd(2 * i, l, mid, x, y);
  upd(2 * i + 1, mid + 1, r, x, y);
  fill(i);
}
int query(int i, int l, int r, int x, int y) {
  if (lazy[i]) {
    swap(seg[i][0], seg[i][1]);
    swap(seg[i][2], seg[i][3]);
    if (l != r) lazy[2 * i] ^= 1, lazy[2 * i + 1] ^= 1;
    lazy[i] = 0;
  }
  return seg[i][2];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, q, l, r;
  string x;
  cin >> n >> q;
  cin >> s;
  s = "0" + s;
  build(1, 1, n);
  while (q--) {
    cin >> x;
    if (x[0] == 'c')
      cout << query(1, 1, n, 1, n) << "\n";
    else {
      cin >> l >> r;
      upd(1, 1, n, l, r);
    }
  }
}
