#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 1000;
const int oo = 1e9 + 7;
int N, M;
int A[MAXN];
struct DATA {
  int sum4, sum7, sum47, sum74;
};
struct SegmentTree {
  DATA ST[4 * MAXN];
  DATA MERGE(DATA &A, DATA &B) {
    DATA C = {0, 0, 0, 0};
    C.sum4 = A.sum4 + B.sum4;
    C.sum7 = A.sum7 + B.sum7;
    C.sum47 = max(C.sum47, A.sum4 + B.sum7);
    C.sum47 = max(C.sum47, A.sum47 + B.sum7);
    C.sum47 = max(C.sum47, A.sum4 + B.sum47);
    C.sum74 = max(C.sum74, A.sum7 + B.sum4);
    C.sum74 = max(C.sum74, A.sum74 + B.sum4);
    C.sum74 = max(C.sum74, A.sum7 + B.sum74);
    return C;
  }
  void build(int id, int l, int r) {
    if (l == r) {
      if (A[l] == 4)
        ST[id] = {1, 0, 1, 1};
      else
        ST[id] = {0, 1, 1, 1};
      lazy[id] = 0;
      return;
    }
    int mid = ((l + r) >> 1);
    build((id << 1), l, mid);
    build((id << 1 | 1), mid + 1, r);
    ST[id] = MERGE(ST[(id << 1)], ST[(id << 1 | 1)]);
    lazy[id] = 0;
  }
  int lazy[4 * MAXN];
  void down(int id, int l, int r) {
    if (!lazy[id]) return;
    int val = lazy[id];
    if (l != r) {
      lazy[(id << 1)] += 1;
      lazy[(id << 1)] %= 2;
      swap(ST[(id << 1)].sum4, ST[(id << 1)].sum7);
      swap(ST[(id << 1)].sum47, ST[(id << 1)].sum74);
      lazy[(id << 1 | 1)] += 1;
      lazy[(id << 1 | 1)] %= 2;
      swap(ST[(id << 1 | 1)].sum4, ST[(id << 1 | 1)].sum7);
      swap(ST[(id << 1 | 1)].sum47, ST[(id << 1 | 1)].sum74);
    }
    lazy[id] = 0;
  }
  void update(int id, int l, int r, int u, int v) {
    if (v < l || r < u) return;
    down(id, l, r);
    if (u <= l && r <= v) {
      swap(ST[id].sum4, ST[id].sum7);
      swap(ST[id].sum47, ST[id].sum74);
      lazy[id] += 1;
      lazy[id] %= 2;
      down(id, l, r);
      return;
    }
    int mid = ((l + r) >> 1);
    update((id << 1), l, mid, u, v);
    update((id << 1 | 1), mid + 1, r, u, v);
    ST[id] = MERGE(ST[(id << 1)], ST[(id << 1 | 1)]);
  }
  DATA get(int id, int l, int r, int u, int v) {
    if (v < l || r < u) return {-oo, -oo, -oo, -oo};
    down(id, l, r);
    if (u <= l && r <= v) return ST[id];
    int mid = ((l + r) >> 1);
    DATA A = get((id << 1), l, mid, u, v);
    DATA B = get((id << 1 | 1), mid + 1, r, u, v);
    return MERGE(A, B);
  }
} IT;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> N >> M;
  for (int i = 1; i <= N; ++i) {
    char ch;
    cin >> ch;
    A[i] = ch - '0';
  }
  IT.build(1, 1, N);
  for (int i = 1; i <= M; ++i) {
    string type;
    cin >> type;
    if (type[0] == 'c') {
      DATA ANS = IT.get(1, 1, N, 1, N);
      int RES = 0;
      RES = max(RES, ANS.sum4);
      RES = max(RES, ANS.sum7);
      RES = max(RES, ANS.sum47);
      cout << RES << '\n';
    } else {
      int u, v;
      cin >> u >> v;
      IT.update(1, 1, N, u, v);
    }
  }
}
