#include <bits/stdc++.h>
using namespace std;
struct luck {
  int n4, n7, n47, n74;
  bool rev;
  luck() {
    n4 = n7 = n74 = n47 = 0;
    rev = false;
  }
};
const int maxn = 1e6;
int k;
luck seg[4 * maxn];
string ss;
void zero(luck &a) {
  a.n4 = a.n7 = a.n74 = a.n47 = 0;
  a.rev = false;
}
luck merge(luck a, luck b, int x) {
  luck ret;
  ret.rev = seg[x].rev;
  ret.n4 = a.n4 + b.n4;
  ret.n7 = b.n7 + a.n7;
  ret.n47 = max(a.n4 + b.n47, a.n47 + b.n7);
  ret.n74 = max(a.n7 + b.n74, a.n74 + b.n4);
  if (seg[x].rev) {
    swap(ret.n4, ret.n7);
    swap(ret.n47, ret.n74);
  }
  return ret;
}
void update(int x) { seg[x] = merge(seg[2 * x], seg[2 * x + 1], x); }
void make(int s = 0, int e = k, int x = 1) {
  if (e == s + 1) {
    if (ss[s] == '7')
      seg[x].n7 = 1;
    else
      seg[x].n4 = 1;
    seg[x].n47 = seg[x].n74 = 1;
    seg[x].rev = false;
    return;
  }
  int mid = (s + e) / 2;
  make(s, mid, 2 * x);
  make(mid, e, 2 * x + 1);
  update(x);
}
void get(int l, int r, int s = 0, int e = k, int x = 1) {
  if (l <= s && e <= r) {
    swap(seg[x].n47, seg[x].n74);
    swap(seg[x].n7, seg[x].n4);
    seg[x].rev = !seg[x].rev;
    return;
  }
  int mid = (s + e) / 2;
  if (l < mid) get(l, r, s, mid, 2 * x);
  if (r > mid) get(l, r, mid, e, 2 * x + 1);
  update(x);
  return;
}
int main() {
  int l;
  cin >> k >> l;
  cin >> ss;
  make();
  for (int i = 0; i < l; i++) {
    string a;
    cin >> a;
    if (a[0] == 's') {
      int b, c;
      scanf("%d%d", &b, &c);
      get(b - 1, c);
    }
    if (a == "count") {
      printf("%d\n", seg[1].n47);
    }
  }
  return 0;
}
