#include <bits/stdc++.h>
using namespace std;
const long long MoD1 = 7 + 1e9;
const long long MoD2 = 1 + 1e7;
const long long INF32 = 5 + 2e9;
const long long INF64 = 5 + 1e18;
const long long MAX = 5 + 1e6;
int N, M, a[MAX];
string s;
struct Node {
  int LIS, LDS;
  int Cz, Co;
  Node() {}
  Node(int z, int o) {
    Cz = z;
    Co = o;
    LIS = LDS = o + z;
  }
} T[4 * MAX];
bool LZ[8 * MAX];
Node Merge(Node &a, Node &b) {
  Node res(a.Cz + b.Cz, a.Co + b.Co);
  res.LIS = max({res.Cz, res.Co, a.Cz + b.LIS, a.LIS + b.Co, a.Cz + b.Co});
  res.LDS = max({res.Cz, res.Co, a.Co + b.LDS, a.LDS + b.Cz, a.Co + b.Cz});
  return res;
}
Node build(int x = 1, int l = 1, int r = N) {
  if (l == r) return T[x] = Node(!a[l], a[l]);
  int mid = l + r >> 1, x1 = x << 1, x2 = x << 1 | 1;
  Node c1 = build(x1, l, mid);
  Node c2 = build(x2, mid + 1, r);
  return T[x] = Merge(c1, c2);
}
void pushLZ(int x) {
  if (!LZ[x]) return;
  Node &a = T[x];
  swap(a.LIS, a.LDS);
  swap(a.Cz, a.Co);
  LZ[x << 1] = !LZ[x << 1];
  LZ[x << 1 | 1] = !LZ[x << 1 | 1];
  LZ[x] = 0;
}
Node query(int L, int R, int x = 1, int l = 1, int r = N) {
  pushLZ(x);
  if (r < L || l > R) return Node(0, 0);
  if (L <= l && r <= R) return T[x];
  int mid = l + r >> 1, x1 = x << 1, x2 = x << 1 | 1;
  Node c1 = query(L, R, x1, l, mid);
  Node c2 = query(L, R, x2, mid + 1, r);
  return Merge(c1, c2);
}
Node update(int L, int R, int x = 1, int l = 1, int r = N) {
  pushLZ(x);
  if (r < L || l > R) return T[x];
  if (L <= l && r <= R) {
    LZ[x] = 1;
    pushLZ(x);
    return T[x];
  }
  int mid = l + r >> 1, x1 = x << 1, x2 = x << 1 | 1;
  Node c1 = update(L, R, x1, l, mid);
  Node c2 = update(L, R, x2, mid + 1, r);
  return T[x] = Merge(c1, c2);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> N >> M;
  for (int i = 1; i <= N; i++) {
    char c;
    cin >> c;
    a[i] = (c == '7');
  }
  build();
  while (M--) {
    cin >> s;
    if (s[0] == 'c')
      cout << T[1].LIS << endl;
    else {
      int l, r;
      cin >> l >> r;
      update(l, r);
    }
  }
  return 0;
}
