#include <bits/stdc++.h>
const long long N = 2000005;
const long long mod = 1e9 + 7;
using namespace std;
struct Node {
  long long n4, n7, n47, n74;
};
vector<char> A(N);
std::vector<Node> tree(N << 2);
vector<bool> lazy(N << 2);
void build(long long node, long long start, long long end) {
  if (start == end) {
    if (A[start] == '4') {
      tree[node].n4 = 1;
      tree[node].n47 = 1;
      tree[node].n74 = 1;
    } else {
      tree[node].n7 = 1;
      tree[node].n47 = 1;
      tree[node].n74 = 1;
    }
  } else {
    long long mid = (start + end) / 2;
    build(2 * node, start, mid);
    build(2 * node + 1, mid + 1, end);
    tree[node].n4 = (tree[node * 2].n4 + tree[node * 2 + 1].n4);
    tree[node].n7 = (tree[node * 2].n7 + tree[node * 2 + 1].n7);
    tree[node].n47 = max({tree[node * 2].n4 + tree[node * 2 + 1].n7,
                          tree[node * 2].n4 + tree[node * 2 + 1].n47,
                          tree[node * 2].n47 + tree[node * 2 + 1].n7});
    tree[node].n74 = max({tree[node * 2].n7 + tree[node * 2 + 1].n4,
                          tree[node * 2].n7 + tree[node * 2 + 1].n74,
                          tree[node * 2].n74 + tree[node * 2 + 1].n4});
  }
}
void change(long long node) {
  swap(tree[node].n4, tree[node].n7);
  swap(tree[node].n47, tree[node].n74);
}
void update(long long node, long long start, long long end, long long left,
            long long right) {
  if (lazy[node] != 0) {
    change(node);
    if (start != end) {
      lazy[2 * node] = lazy[2 * node] ^ 1;
      lazy[2 * node + 1] = lazy[2 * node + 1] ^ 1;
    }
    lazy[node] = 0;
  }
  if (end < left || start > right || end < start) return;
  if (start >= left and right >= end) {
    change(node);
    if (start != end) {
      lazy[2 * node] = lazy[2 * node] ^ 1;
      lazy[2 * node + 1] = lazy[2 * node + 1] ^ 1;
    }
  } else {
    long long mid = (start + end) / 2;
    update(2 * node, start, mid, left, right);
    update(2 * node + 1, mid + 1, end, left, right);
    tree[node].n4 = (tree[node * 2].n4 + tree[node * 2 + 1].n4);
    tree[node].n7 = (tree[node * 2].n7 + tree[node * 2 + 1].n7);
    tree[node].n47 = max({tree[node * 2].n4 + tree[node * 2 + 1].n7,
                          tree[node * 2].n4 + tree[node * 2 + 1].n47,
                          tree[node * 2].n47 + tree[node * 2 + 1].n7});
    tree[node].n74 = max({tree[node * 2].n7 + tree[node * 2 + 1].n4,
                          tree[node * 2].n7 + tree[node * 2 + 1].n74,
                          tree[node * 2].n74 + tree[node * 2 + 1].n4});
  }
}
long long query(long long node, long long start, long long end, long long left,
                long long right) {
  if (lazy[node] != 0) {
    change(node);
    if (start != end) {
      lazy[2 * node] = lazy[2 * node] ^ 1;
      lazy[2 * node + 1] = lazy[2 * node + 1] ^ 1;
    }
    lazy[node] = 0;
  }
  if (end < left || start > right || end < start) return INT_MAX;
  if (left <= start and right >= end) {
    return tree[node].n47;
  }
  long long mid = (start + end) / 2;
  long long p1 = 0, p2 = 0;
  p2 = query(2 * node + 1, mid + 1, end, left, right);
  p1 = query(2 * node, start, mid, left, right);
  return max(p1, p2);
}
void solve() {
  long long n, m, k, x = 0, y = 0, c = 0, q, ans = 0;
  cin >> n >> q;
  string s;
  for (long long i = 1; i <= n; ++i) {
    cin >> A[i];
  }
  build(1, 1, n);
  while (q--) {
    cin >> s;
    if (s == "count") {
      cout << tree[1].n47 << '\n';
    } else {
      cin >> x >> y;
      update(1, 1, n, x, y);
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
