#include <bits/stdc++.h>
using namespace std;
int mv1[4] = {0, 0, 1, -1};
int mv2[4] = {1, -1, 0, 0};
int n, m;
int TN[5000001];
int TF[5000001];
int TB[5000001];
int c4[5000001];
int c7[5000001];
bool rev[5000001];
void propagate(int now, int s, int e) {
  if (rev[now]) {
    if (s != e) {
      rev[now * 2] = !rev[now * 2];
      rev[now * 2 + 1] = !rev[now * 2 + 1];
      if (rev[now * 2]) {
        TF[now] =
            max(TB[now * 2] + c4[now * 2 + 1], c7[now * 2] + TB[now * 2 + 1]);
        TB[now] =
            max(TF[now * 2] + c7[now * 2 + 1], c4[now * 2] + TF[now * 2 + 1]);
      } else {
        TF[now] =
            max(TF[now * 2] + c7[now * 2 + 1], c4[now * 2] + TF[now * 2 + 1]);
        TB[now] =
            max(TB[now * 2 + 1] + c7[now * 2], c4[now * 2 + 1] + TB[now * 2]);
      }
    }
    int temp = c4[now];
    c4[now] = c7[now];
    c7[now] = temp;
    rev[now] = 0;
  }
}
void init(int now, int s, int e, int l, int r, int v) {
  if (l > e || r < s) return;
  if (s == e) {
    TF[now] = 1;
    TB[now] = 1;
    if (v == 4) {
      c4[now] = 1;
    } else if (v == 7) {
      c7[now] = 1;
    }
    return;
  }
  int mid = (s + e) / 2;
  init(now * 2, s, mid, l, r, v);
  init(now * 2 + 1, mid + 1, e, l, r, v);
  c4[now] = c4[now * 2] + c4[now * 2 + 1];
  c7[now] = c7[now * 2] + c7[now * 2 + 1];
  TF[now] = max(TF[now * 2] + c7[now * 2 + 1], c4[now * 2] + TF[now * 2 + 1]);
  TB[now] = max(TB[now * 2 + 1] + c7[now * 2], c4[now * 2 + 1] + TB[now * 2]);
}
void update(int now, int s, int e, int l, int r) {
  propagate(now, s, e);
  if (l > e || r < s) return;
  if (l <= s && e <= r) {
    rev[now] = !rev[now];
    propagate(now, s, e);
    return;
  }
  if (s == e) return;
  int mid = (s + e) / 2;
  update(now * 2, s, mid, l, r);
  update(now * 2 + 1, mid + 1, e, l, r);
  c4[now] = c4[now * 2] + c4[now * 2 + 1];
  c7[now] = c7[now * 2] + c7[now * 2 + 1];
  TF[now] = max(TF[now * 2] + c7[now * 2 + 1], c4[now * 2] + TF[now * 2 + 1]);
  TB[now] = max(TB[now * 2 + 1] + c7[now * 2], c4[now * 2 + 1] + TB[now * 2]);
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  string s;
  cin >> s;
  for (int i = 1; i <= n; i++) {
    int v = s[i - 1] - '0';
    init(1, 1, n, i, i, v);
  }
  for (int i = 0; i < m; i++) {
    string q;
    cin >> q;
    if (q == "switch") {
      int l, r;
      cin >> l >> r;
      update(1, 1, n, l, r);
    } else {
      cout << TF[1] << "\n";
    }
  }
}
