#include <bits/stdc++.h>
using namespace std;
const int N = 4e6 + 5, Mod = 1e9 + 7, MAXN = 1e5 + 10, LG = 20, M = 1e7,
          P = 727, Sq = 445 + 5;
const long long inf = 2e18 + 10;
int seg[N][2], f[N], t7[N], t4[N], n, m, m4[N], m7[N];
void Build(int s, int e, int ind) {
  if (e - s == 1) {
    seg[ind][0] = seg[ind][1] = 1;
    if (t7[s] - t7[s - 1] == 1)
      m7[ind] = 1;
    else
      m4[ind] = 1;
    return;
  }
  int mid = (s + e) / 2;
  Build(s, mid, (2 * (ind)));
  Build(mid, e, ((2 * (ind)) + 1));
  seg[ind][0] = max(seg[(2 * (ind))][0] + m7[((2 * (ind)) + 1)],
                    seg[((2 * (ind)) + 1)][0] + m4[(2 * (ind))]);
  seg[ind][1] = max(seg[(2 * (ind))][1] + m4[((2 * (ind)) + 1)],
                    seg[((2 * (ind)) + 1)][1] + m7[(2 * (ind))]);
  m4[ind] = m4[(2 * (ind))] + m4[((2 * (ind)) + 1)];
  m7[ind] = m7[(2 * (ind))] + m7[((2 * (ind)) + 1)];
  return;
}
void Shift(int s, int e, int ind) {
  if (!f[ind]) return;
  swap(seg[(2 * (ind))][0], seg[(2 * (ind))][1]);
  swap(seg[((2 * (ind)) + 1)][0], seg[((2 * (ind)) + 1)][1]);
  swap(m7[(2 * (ind))], m4[(2 * (ind))]);
  swap(m7[((2 * (ind)) + 1)], m4[((2 * (ind)) + 1)]);
  f[ind] = 1 - f[ind];
  f[(2 * (ind))] = 1 - f[(2 * (ind))];
  f[((2 * (ind)) + 1)] = 1 - f[((2 * (ind)) + 1)];
  return;
}
void Change(int s, int e, int ind, int l, int r) {
  if (s >= l && e <= r) {
    swap(seg[ind][0], seg[ind][1]);
    swap(m7[ind], m4[ind]);
    f[ind] = 1 - f[ind];
    return;
  }
  Shift(s, e, ind);
  int mid = (s + e) / 2;
  if (l < mid) Change(s, mid, (2 * (ind)), l, r);
  if (r > mid) Change(mid, e, ((2 * (ind)) + 1), l, r);
  seg[ind][0] = max(seg[(2 * (ind))][0] + m7[((2 * (ind)) + 1)],
                    seg[((2 * (ind)) + 1)][0] + m4[(2 * (ind))]);
  seg[ind][1] = max(seg[(2 * (ind))][1] + m4[((2 * (ind)) + 1)],
                    seg[((2 * (ind)) + 1)][1] + m7[(2 * (ind))]);
  m4[ind] = m4[(2 * (ind))] + m4[((2 * (ind)) + 1)];
  m7[ind] = m7[(2 * (ind))] + m7[((2 * (ind)) + 1)];
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string ss, tt;
  cin >> n >> m >> ss;
  for (int i = 1; i <= n; i++) {
    if (ss[i - 1] == '7')
      t7[i] = t7[i - 1] + 1, t4[i] = t4[i - 1];
    else
      t7[i] = t7[i - 1], t4[i] = t4[i - 1] + 1;
  }
  Build(1, n + 1, 1);
  int l, r;
  for (int i = 1; i <= m; i++) {
    cin >> tt;
    if (tt == "count")
      cout << seg[1][0] << '\n';
    else {
      cin >> l >> r;
      Change(1, n + 1, 1, l, r + 1);
    }
  }
  return 0;
}
