#include <bits/stdc++.h>
int take() {
  int n;
  scanf("%d", &n);
  return n;
}
double ttake() {
  double n;
  scanf("%lf", &n);
  return n;
}
long long takes() {
  long long n;
  scanf("%lld", &n);
  return n;
}
int cas;
using namespace std;
bool approximatelyEqual(float a, float b, float epsilon) {
  return fabs(a - b) <= ((fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}
bool essentiallyEqual(float a, float b, float epsilon) {
  return fabs(a - b) <= ((fabs(a) > fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}
bool definitelyGreaterThan(float a, float b, float epsilon) {
  return (a - b) > ((fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}
bool definitelyLessThan(float a, float b, float epsilon) {
  return (b - a) > ((fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}
string ss;
struct info {
  int four;
  int seven;
  int fourseven;
  int sevenfour;
} tr[4 * 1000005];
int lazy[4 * 1000005];
info put(info t1, info t2) {
  info ptr;
  int f1 = t1.four, f2 = t2.four;
  int s1 = t1.seven, s2 = t2.seven;
  int fs1 = t1.fourseven, fs2 = t2.fourseven;
  int sf1 = t1.sevenfour, sf2 = t2.sevenfour;
  ptr.four = f1 + f2;
  ptr.seven = s1 + s2;
  ptr.fourseven = max(fs1 + s2, max(f1 + fs2, f1 + s1));
  ptr.sevenfour = max(sf1 + f2, max(s1 + sf2, s1 + f1));
  return ptr;
}
void built(int s, int e, int n) {
  if (s > e) return;
  if (s == e) {
    int data = ss[s - 1] - 48;
    tr[n].fourseven = (data == 7);
    tr[n].sevenfour = (data == 4);
    tr[n].four = (data == 4);
    tr[n].seven = (data == 7);
    return;
  }
  int m = s + (e - s) / 2;
  built(s, m, 2 * n);
  built(m + 1, e, 2 * n + 1);
  tr[n] = put(tr[2 * n], tr[2 * n + 1]);
}
void upd(int s, int e, int l, int r, int n) {
  if (lazy[n]) {
    if (lazy[n] % 2) {
      swap(tr[n].four, tr[n].seven);
      swap(tr[n].fourseven, tr[n].sevenfour);
    }
    if (s != e) {
      lazy[2 * n] += lazy[n];
      lazy[2 * n + 1] += lazy[n];
    }
    lazy[n] = 0;
  }
  if (s > e || s > r || e < l) return;
  if (s >= l && e <= r) {
    swap(tr[n].four, tr[n].seven);
    swap(tr[n].fourseven, tr[n].sevenfour);
    if (s != e) {
      lazy[2 * n]++;
      lazy[2 * n + 1]++;
    }
    return;
  }
  int m = s + (e - s) / 2;
  upd(s, m, l, r, 2 * n);
  upd(m + 1, e, l, r, 2 * n + 1);
  tr[n] = put(tr[2 * n], tr[2 * n + 1]);
}
int main() {
  int tc = 1;
  while (tc--) {
    int n = take(), q = take();
    cin >> ss;
    built(1, n, 1);
    while (q--) {
      cin >> ss;
      if (ss == "switch") {
        int l = take(), r = take();
        upd(1, n, l, r, 1);
      } else {
        printf("%d\n", max(tr[1].four, max(tr[1].seven, tr[1].fourseven)));
      }
    }
  }
  { return 0; };
}
