#include <bits/stdc++.h>
using namespace std;
const long long int inf = 1e9;
const long double eps = 1e-9;
const long double pi = acos(-1);
const long long int mod = 1000000007;
long long int powmod(long long int a, long long int b) {
  long long int res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
const int MAXN = 1000010;
struct s {
  int n4, n7, n47, n74;
};
s tree[3 * MAXN];
string in;
int n, m;
bool lazy[3 * MAXN];
void build(int node, int b, int e) {
  if (b == e) {
    if (in[b] == '4') {
      tree[node].n4 = 1;
      tree[node].n7 = 0;
      tree[node].n47 = 1;
      tree[node].n74 = 1;
    } else {
      tree[node].n4 = 0;
      tree[node].n7 = 1;
      tree[node].n47 = 1;
      tree[node].n74 = 1;
    }
  } else {
    build(2 * node, b, (b + e) / 2);
    build(2 * node + 1, (b + e) / 2 + 1, e);
    tree[node].n4 = tree[2 * node].n4 + tree[2 * node + 1].n4;
    tree[node].n7 = tree[2 * node].n7 + tree[2 * node + 1].n7;
    tree[node].n47 = max(max(tree[2 * node].n47 + tree[2 * node + 1].n7,
                             tree[2 * node].n4 + tree[2 * node + 1].n47),
                         tree[2 * node].n4 + tree[2 * node + 1].n7);
    tree[node].n74 = max(max(tree[2 * node].n74 + tree[2 * node + 1].n4,
                             tree[2 * node].n7 + tree[2 * node + 1].n74),
                         tree[2 * node].n7 + tree[2 * node + 1].n4);
  }
}
void update(int node, int b, int e, int l, int r) {
  if (lazy[node]) {
    swap(tree[node].n4, tree[node].n7);
    swap(tree[node].n47, tree[node].n74);
    if (b != e) {
      lazy[2 * node] ^= 1;
      lazy[2 * node + 1] ^= 1;
    }
    lazy[node] = false;
  }
  if (b > r || e < l) return;
  if (b >= l && e <= r) {
    swap(tree[node].n4, tree[node].n7);
    swap(tree[node].n47, tree[node].n74);
    if (b != e) {
      lazy[2 * node] ^= 1;
      lazy[2 * node + 1] ^= 1;
    }
    return;
  }
  update(2 * node, b, (b + e) / 2, l, r);
  update(2 * node + 1, (b + e) / 2 + 1, e, l, r);
  tree[node].n4 = tree[2 * node].n4 + tree[2 * node + 1].n4;
  tree[node].n7 = tree[2 * node].n7 + tree[2 * node + 1].n7;
  tree[node].n47 = max(max(tree[2 * node].n47 + tree[2 * node + 1].n7,
                           tree[2 * node].n4 + tree[2 * node + 1].n47),
                       tree[2 * node].n4 + tree[2 * node + 1].n7);
  tree[node].n74 = max(max(tree[2 * node].n74 + tree[2 * node + 1].n4,
                           tree[2 * node].n7 + tree[2 * node + 1].n74),
                       tree[2 * node].n7 + tree[2 * node + 1].n4);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  cin >> in;
  build(1, 0, n - 1);
  while (m--) {
    string yo;
    int l, r;
    cin >> yo;
    if (yo[0] == 's') {
      cin >> l >> r;
      l--;
      r--;
      update(1, 0, n - 1, l, r);
    } else {
      cout << tree[1].n47 << '\n';
    }
  }
  return 0;
}
