#include <bits/stdc++.h>
using namespace std;
struct node {
  bool lazy_switch;
  int longest_4;
  int longest_7;
  int longest_47;
  int longest_74;
  node(char c = '4')
      : lazy_switch(false),
        longest_4(0),
        longest_7(0),
        longest_47(0),
        longest_74(0) {
    lazy_switch = false;
    if (c == '4')
      longest_4 = 1;
    else
      longest_7 = 1;
  }
  static node identity(void) {
    node result;
    result.longest_4 = result.longest_7 = 0;
    return result;
  }
  void flip() {
    lazy_switch = !lazy_switch;
    swap(longest_4, longest_7);
    swap(longest_47, longest_74);
  }
  void merge(const node& L, const node& R) {
    longest_4 = L.longest_4 + R.longest_4;
    longest_7 = L.longest_7 + R.longest_7;
    longest_47 = max(L.longest_47, R.longest_47);
    if (L.longest_4 != 0 && R.longest_7 != 0)
      longest_47 = max(longest_47, L.longest_4 + R.longest_7);
    if (L.longest_4 != 0 && R.longest_47 != 0)
      longest_47 = max(longest_47, L.longest_4 + R.longest_47);
    if (L.longest_47 != 0 && R.longest_7 != 0)
      longest_47 = max(longest_47, L.longest_47 + R.longest_7);
    longest_74 = max(L.longest_74, R.longest_74);
    if (L.longest_7 != 0 && R.longest_4 != 0)
      longest_74 = max(longest_74, L.longest_7 + R.longest_4);
    if (L.longest_7 != 0 && R.longest_74 != 0)
      longest_74 = max(longest_74, L.longest_7 + R.longest_74);
    if (L.longest_74 != 0 && R.longest_4 != 0)
      longest_74 = max(longest_74, L.longest_74 + R.longest_4);
  }
  int get(void) {
    int result = longest_4;
    result = max(result, longest_7);
    result = max(result, longest_47);
    return result;
  }
};
struct segment_tree {
  int n, pow2;
  node* A;
  segment_tree(const string& s) {
    n = s.size();
    pow2 = 1;
    while (pow2 < n) pow2 <<= 1;
    A = new node[pow2 * 2];
    for (int i = 0; i < n; i++) A[i + pow2] = node(s[i]);
    for (int i = n + pow2; i < 2 * pow2; i++) A[i] = node('c');
    for (int i = pow2 - 1; i >= 1; i--) {
      A[i].merge(A[i << 1], A[(i << 1) + 1]);
      A[i].lazy_switch = false;
    }
  }
  void flip(int L, int R) { flip(L, R, 1, 0, pow2 - 1); }
  void propagate_switch(int ind) {
    if (A[ind].lazy_switch) {
      A[ind << 1].flip();
      A[(ind << 1) + 1].flip();
    }
  }
  void flip(int L, int R, int ind, int LB, int RB) {
    if (L > R) return;
    if (LB == L && R == RB) {
      A[ind].flip();
      return;
    }
    int MB = (LB + RB) >> 1;
    propagate_switch(ind);
    flip(L, min(MB, R), ind << 1, LB, MB);
    flip(max(MB + 1, L), R, (ind << 1) + 1, MB + 1, RB);
    A[ind].merge(A[ind << 1], A[(ind << 1) + 1]);
    A[ind].lazy_switch = false;
  }
  int count(void) {
    node temp = query(0, n - 1, 1, 0, pow2 - 1);
    return temp.get();
  }
  node query(int L, int R, int ind, int LB, int RB) {
    if (L > R) return node::identity();
    if (LB == L && R == RB) return A[ind];
    int MB = (LB + RB) >> 1;
    propagate_switch(ind);
    node Left = query(L, min(MB, R), ind << 1, LB, MB);
    node Right = query(max(MB + 1, L), R, (ind << 1) + 1, MB + 1, RB);
    node result;
    result.merge(Left, Right);
    result.lazy_switch = false;
    return result;
  }
  ~segment_tree() { delete[] A; }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  string s;
  cin >> s;
  segment_tree T(s);
  string query_type;
  int l, r;
  for (int i = 0; i < m; i++) {
    cin >> query_type;
    if (query_type == "count") {
      cout << T.count() << '\n';
    } else {
      cin >> l >> r;
      T.flip(l - 1, r - 1);
    }
  }
  return 0;
}
