#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 500;
char num[N];
typedef struct Dat {
  long long n4, n7, n47, n74;
} Dat;
long long mx3(long long a, long long b, long long c) {
  return max(a, max(b, c));
}
struct Tree {
  bool add[4 * N];
  Dat d[4 * N];
  Dat merge(Dat lft, Dat rht) {
    Dat res;
    res.n4 = lft.n4 + rht.n4;
    res.n7 = lft.n7 + rht.n7;
    res.n47 = mx3(lft.n4 + rht.n7, lft.n47 + rht.n7, lft.n4 + rht.n47);
    res.n74 = mx3(lft.n7 + rht.n4, lft.n74 + rht.n4, lft.n7 + rht.n74);
    return res;
  }
  void init(int x, int l, int r) {
    if (l == r) {
      Dat res;
      res.n47 = res.n74 = 0;
      if (num[l] == '4') {
        res.n4 = 1;
        res.n7 = 0;
      } else {
        res.n4 = 0;
        res.n7 = 1;
      }
      add[x] = false;
      d[x] = res;
      return;
    }
    int mid = (l + r) / 2;
    init(x * 2 + 1, l, mid);
    init(x * 2 + 2, mid + 1, r);
    add[x] = false;
    d[x] = merge(d[x * 2 + 1], d[x * 2 + 2]);
  }
  void swap(int x) {
    long long tmp = d[x].n4;
    d[x].n4 = d[x].n7;
    d[x].n7 = tmp;
    tmp = d[x].n47;
    d[x].n47 = d[x].n74;
    d[x].n74 = tmp;
  }
  void push_down(int x, int l, int r) {
    if (add[x]) {
      if (l < r) {
        int mid = (l + r) / 2;
        swap(x * 2 + 1);
        swap(x * 2 + 2);
        add[x * 2 + 1] = !add[x * 2 + 1];
        add[x * 2 + 2] = !add[x * 2 + 2];
      }
      add[x] = false;
    }
  }
  Dat query(int a, int b, int x, int l, int r) {
    int mid = (l + r) / 2;
    assert(!(r < a || l > b));
    push_down(x, l, r);
    if (l >= a && r <= b) {
      return d[x];
    }
    Dat LHS = query(a, b, x * 2 + 1, l, mid);
    Dat RHS = query(a, b, x * 2 + 2, mid + 1, r);
    return merge(LHS, RHS);
  }
  void update(int a, int b, int x, int l, int r) {
    int mid = (l + r) / 2;
    if (r < a || l > b) return;
    if (l < r) push_down(x, l, r);
    if (l >= a && r <= b) {
      swap(x);
      add[x] = true;
      return;
    }
    update(a, b, x * 2 + 1, l, mid);
    update(a, b, x * 2 + 2, mid + 1, r);
    d[x] = merge(d[x * 2 + 1], d[x * 2 + 2]);
  }
  void show() {
    cout << d[0].n47 << endl;
    cout << d[1].n47 << endl;
    cout << d[2].n47 << endl;
  }
} tree;
int n, a[1000001], m;
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  cin >> num;
  tree.init(0, 0, n - 1);
  for (int i = 0; i < m; i++) {
    char cmd[7];
    cin >> cmd;
    if (strcmp(cmd, "count") == 0) {
      Dat tmp = tree.query(0, n - 1, 0, 0, n - 1);
      cout << mx3(tmp.n47, tmp.n7, tmp.n4) << "\n";
    } else {
      int l, r;
      cin >> l >> r;
      tree.update(l - 1, r - 1, 0, 0, n - 1);
    }
  }
}
