#include<bits/stdc++.h>
using namespace std;

typedef int ll;
#define MAXN 1000005

struct node
{

	int no_4;
	int no_7;
	int no_47;
	int no_74;
	int prop;

	node(int a=0, int b=0, int c=0, int d=0, int e=0) : no_47(c), no_4(a), no_74(d), no_7(b), prop(e) {}
};

ll n;
node tree[4*MAXN];

#define LEFT(x) (x*2)
#define RIGHT(x) (x*2+1)
#define MAX(x, y) (max(x,y))
#define SUM(x,y) (x+y)
#define XOR(x,y) (x^y)
#define OR(x,y) (x|y)

#define FUNC func
#define ASSOCIATIVE_CONSTANT 0

/*
inline void fastIO(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
*/
inline int max(int a, int b, int c){
	return max(a, max(b, c));
}

inline node func(node a, node b)
{
	return node(a.no_4+b.no_4, a.no_7+b.no_7, max(a.no_47+b.no_7, a.no_4+b.no_47, a.no_4+b.no_7),
			max(a.no_74+b.no_4, a.no_7+b.no_74, a.no_7+b.no_4));
}

string hell;

void build(int root, int tree_left, int tree_right)
{
	if(tree_left == tree_right){
		if(hell[tree_left] == '4')
			tree[root] = node(1, 0, 1, 1);
		else
			tree[root] = node(0, 1, 1, 1);
	}
	else{
		ll tree_mid = (tree_left + tree_right)/2;
		build(LEFT(root), tree_left, tree_mid); /// Building the left tree
		build(RIGHT(root), tree_mid+1, tree_right); /// Building the right tree
		tree[root] = func(tree[LEFT(root)], tree[RIGHT(root)]); /// Preprocessing the data
	}
}
/*
ll query(ll root, ll tree_left, ll tree_right, ll query_left, ll query_right)
{
	// cout << root << " " << tree_left << " " << tree_right << " " << query_left << " " << query_right << "\n";
	if(query_left >  query_right)
		return ASSOCIATIVE_CONSTANT; /// 0 for sum, INT_MAX for min, INT_MIN for max, ...
	if(tree_left == query_left && tree_right == query_right)
		return tree[root]; /// Bottom of the tree
	ll tree_mid = (tree_left + tree_right)/2;
	return FUNC(query(LEFT(root), tree_left, tree_mid, query_left, min(query_right, tree_mid)),
			query(RIGHT(root), tree_mid+1, tree_right, max(query_left, tree_mid+1), query_right));
}

void update(ll root, ll tree_left, ll tree_right, ll pos, ll val)
{
	if(tree_left == tree_right)
		tree[root] = val; /// Update the bottom
	else{
		ll tree_mid = (tree_left + tree_right)/2;
		if(pos>tree_mid) /// In the right sub-tree
			update(RIGHT(root), tree_mid+1, tree_right, pos, val);
		else /// In the left sub-tree
			update(LEFT(root), tree_left, tree_mid, pos, val);
		/// Updating
		tree[root] = FUNC(tree[LEFT(root)], tree[RIGHT(root)]);
	}
}
*/
void updateRange(ll root, ll tree_left, ll tree_right, ll up_left, ll up_right, ll val)
{
	//printf("START: %d %d %d %d %d %d\n", root, tree_left, tree_right, up_left, up_right, tree[root].prop);
	if(tree[root].prop){
		/// This node needs to be updated
		//printf("LAZY: %d %d %d %d %d %d\n", root, tree_left, tree_right, up_left, up_right, val);
		swap(tree[root].no_47, tree[root].no_74);
		swap(tree[root].no_4, tree[root].no_7);

		if(tree_left != tree_right){
			tree[LEFT(root)].prop ^= 1;
			tree[RIGHT(root)].prop ^= 1;
		}

		tree[root].prop = 0;
	}

	if(tree_left > up_right || tree_left > tree_right || tree_right < up_left)
		return;
	else if(up_left <= tree_left && tree_right <= up_right){
		//printf("AKA: %d %d %d %d %d %d\n", root, tree_left, tree_right, up_left, up_right, val);
		swap(tree[root].no_47, tree[root].no_74);
		swap(tree[root].no_4, tree[root].no_7);
		int i = root;
		//printf("(%d,%d,%d,%d,%d) ", tree[i].no_4, tree[i].no_7, tree[i].no_47, tree[i].no_74, tree[i].prop);
		if(tree_left != tree_right){
			tree[LEFT(root)].prop ^= 1;
			tree[RIGHT(root)].prop ^= 1;
		}
	}
	else{
		ll tree_mid = (tree_left + tree_right)/2;
		updateRange(LEFT(root), tree_left, tree_mid, up_left, up_right, val);
		updateRange(RIGHT(root), tree_mid+1, tree_right, up_left, up_right, val);

		tree[root] = FUNC(tree[LEFT((root))], tree[RIGHT(root)]);
	}
	return;
}

void print_segment_tree(int lim = 40)
{
	printf("\nSegment tree:\n");
	for(int i=1, j=1; i<lim; ++i){
		if(i == (1<<j)){
			++j;
			printf("\n");
		}
		printf("(%d,%d,%d,%d,%d) ", tree[i].no_4, tree[i].no_7, tree[i].no_47, tree[i].no_74, tree[i].prop);
	}
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n, m, p, q;
	cin >> n >> m;

	string x;
	cin >> hell;

	build(1, 0, n-1);
	while(m--){
		cin >> x;
		if(x[0] == 'c'){
			cout << tree[1].no_47 << endl;
			//print_segment_tree(16);
		}
		else{
			cin >> p >> q;
			updateRange(1, 0, n-1, --p, --q, p);
			//print_segment_tree(16);
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
#define MAXN 300005

struct node
{

	int no_4;
	int no_7;
	int no_47;
	int no_74;

	node(int a=0, int b=0, int c=0, int d=0) : no_47(c), no_4(a), no_74(d), no_7(b) {}
};

ll n;
node tree[4*MAXN];

#define LEFT(x) (x*2)
#define RIGHT(x) (x*2+1)
#define MAX(x, y) (max(x,y))
#define SUM(x,y) (x+y)
#define XOR(x,y) (x^y)
#define OR(x,y) (x|y)

#define FUNC XOR
#define ASSOCIATIVE_CONSTANT 0

/*
inline void fastIO(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

inline int max(int a, int b, int c){
	return max(a, max(b, c));
}*/

inline node func(node a, node b)
{
	return node(a.no_4+b.no_4, a.no_7+b.no_7, max(a.no_47+b.no_7, a.no_4+b.no_47),
			max(a.no_74+b.no_4, a.no_7+b.no_74));
}

string hell;

void build(int root, int tree_left, int tree_right)
{
	if(tree_left == tree_right){
		if(hell[tree_left] == '4')
			tree[root] = node(1, 0, 1, 1);
		else
			tree[root] = node(0, 1, 1, 1);
	}
	else{
		ll tree_mid = (tree_left + tree_right)/2;
		build(LEFT(root), tree_left, tree_mid); /// Building the left tree
		build(RIGHT(root), tree_mid+1, tree_right); /// Building the right tree
		tree[root] = func(tree[LEFT(root)], tree[RIGHT(root)]); /// Preprocessing the data
	}
}
/*
ll query(ll root, ll tree_left, ll tree_right, ll query_left, ll query_right)
{
	// cout << root << " " << tree_left << " " << tree_right << " " << query_left << " " << query_right << "\n";
	if(query_left >  query_right)
		return ASSOCIATIVE_CONSTANT; /// 0 for sum, INT_MAX for min, INT_MIN for max, ...
	if(tree_left == query_left && tree_right == query_right)
		return tree[root]; /// Bottom of the tree
	ll tree_mid = (tree_left + tree_right)/2;
	return FUNC(query(LEFT(root), tree_left, tree_mid, query_left, min(query_right, tree_mid)),
			query(RIGHT(root), tree_mid+1, tree_right, max(query_left, tree_mid+1), query_right));
}

void update(ll root, ll tree_left, ll tree_right, ll pos, ll val)
{
	if(tree_left == tree_right)
		tree[root] = val; /// Update the bottom
	else{
		ll tree_mid = (tree_left + tree_right)/2;
		if(pos>tree_mid) /// In the right sub-tree
			update(RIGHT(root), tree_mid+1, tree_right, pos, val);
		else /// In the left sub-tree
			update(LEFT(root), tree_left, tree_mid, pos, val);
		/// Updating
		tree[root] = FUNC(tree[LEFT(root)], tree[RIGHT(root)]);
	}
}
*/
void updateRange(int node, int start, int end, int l, int r)
{
    if (start > end || start > r || end < l)
        return;

    if (start == end)
    {
        swap(tree[node].no_47, tree[node].no_74);
        swap(tree[node].no_7, tree[node].no_4);
        return;
    }

    int mid = (start + end) / 2;
    updateRange(LEFT(node), start, mid, l, r);
    updateRange(RIGHT(node), mid + 1, end, l, r);

    tree[node] = func(tree[LEFT(node)], tree[RIGHT(node)]);
}

void print_segment_tree(int lim = 40)
{
	printf("\nSegment tree:\n");
	for(int i=1, j=1; i<lim; ++i){
		if(i == (1<<j)){
			++j;
			printf("\n");
		}
		printf("(%d,%d,%d,%d) ", tree[i].no_4, tree[i].no_7, tree[i].no_47, tree[i].no_74);
	}
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n, m, p, q;
	cin >> n >> m;

	string x;
	cin >> hell;

	build(1, 0, n-1);
	while(m--){
		cin >> x;
		if(x[0] == 'c'){
			cout << tree[1].no_47 << endl;
			//print_segment_tree(7);
		}
		else{
			cin >> p >> q;
			updateRange(1, 0, n-1, --p, --q);
			//print_segment_tree(7);
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
#define MAXN 300005

struct node
{

	int no_4;
	int no_7;
	int no_47;
	int no_74;

	node(int a=0, int b=0, int c=0, int d=0) : no_47(c), no_4(a), no_74(d), no_7(b) {}
};

ll n;
node tree[4*MAXN];

#define LEFT(x) (x*2)
#define RIGHT(x) (x*2+1)
#define MAX(x, y) (max(x,y))
#define SUM(x,y) (x+y)
#define XOR(x,y) (x^y)
#define OR(x,y) (x|y)

#define FUNC XOR
#define ASSOCIATIVE_CONSTANT 0

inline void fastIO(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

inline int max(int a, int b, int c){
	return max(a, max(b, c));
}

inline node func(node a, node b)
{
	return node(a.no_4+b.no_4, a.no_7+b.no_7, max(a.no_47+b.no_7, a.no_4+b.no_47),
			max(a.no_74+b.no_4, a.no_7+b.no_74));
}

void build(string arr, int root, int tree_left, int tree_right)
{
	if(tree_left == tree_right){
		if(arr[tree_left] == '4')
			tree[root] = node(1, 0, 1, 1);
		else
			tree[root] = node(0, 1, 1, 1);
	}
	else{
		ll tree_mid = (tree_left + tree_right)/2;
		build(arr, LEFT(root), tree_left, tree_mid); /// Building the left tree
		build(arr, RIGHT(root), tree_mid+1, tree_right); /// Building the right tree
		tree[root] = func(tree[LEFT(root)], tree[RIGHT(root)]); /// Preprocessing the data
	}
}
/*
ll query(ll root, ll tree_left, ll tree_right, ll query_left, ll query_right)
{
	// cout << root << " " << tree_left << " " << tree_right << " " << query_left << " " << query_right << "\n";
	if(query_left >  query_right)
		return ASSOCIATIVE_CONSTANT; /// 0 for sum, INT_MAX for min, INT_MIN for max, ...
	if(tree_left == query_left && tree_right == query_right)
		return tree[root]; /// Bottom of the tree
	ll tree_mid = (tree_left + tree_right)/2;
	return FUNC(query(LEFT(root), tree_left, tree_mid, query_left, min(query_right, tree_mid)),
			query(RIGHT(root), tree_mid+1, tree_right, max(query_left, tree_mid+1), query_right));
}

void update(ll root, ll tree_left, ll tree_right, ll pos, ll val)
{
	if(tree_left == tree_right)
		tree[root] = val; /// Update the bottom
	else{
		ll tree_mid = (tree_left + tree_right)/2;
		if(pos>tree_mid) /// In the right sub-tree
			update(RIGHT(root), tree_mid+1, tree_right, pos, val);
		else /// In the left sub-tree
			update(LEFT(root), tree_left, tree_mid, pos, val);
		/// Updating
		tree[root] = FUNC(tree[LEFT(root)], tree[RIGHT(root)]);
	}
}
*/
void updateRange(int node, int start, int end, int l, int r, int val)
{
    if (start > end || start > r || end < l)
        return;

    if (start == end)
    {
        swap(tree[node].no_47, tree[node].no_74);
        swap(tree[node].no_7, tree[node].no_4);
        return;
    }

    int mid = (start + end) / 2;
    updateRange(LEFT(node), start, mid, l, r, val);
    updateRange(RIGHT(node), mid + 1, end, l, r, val);

    tree[node] = func(tree[LEFT(node)], tree[RIGHT(node)]);
}

void print_segment_tree(int lim = 40)
{
	printf("\nSegment tree:\n");
	for(int i=1, j=1; i<lim; ++i){
		if(i == (1<<j)){
			++j;
			printf("\n");
		}
		printf("(%d,%d,%d,%d) ", tree[i].no_4, tree[i].no_7, tree[i].no_47, tree[i].no_74);
	}
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n, m, p, q;
	cin >> n >> m;

	string x, hell, c("count");
	getline(cin, x);
	getline(cin, hell);

	build(hell, 1, 0, n-1);
	while(m--){
		cin >> x;
		if(x == c){
			cout << tree[1].no_47 << endl;
			//print_segment_tree(7);
		}
		else{
			cin >> p >> q;
			updateRange(1, 0, n-1, --p, --q, m*m);
			//print_segment_tree(7);
		}
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define int long long

template <class Data, class Update>
struct segment_tree_lazy {

  vector<Data> tree;
  vector<Update> updates;
  int size;

  Data (*combine)(Data, Data);
  Update (*combine_u)(Update, Update);
  Data (*apply)(Data, Update);
  Data unity;
  Update identity;

  Data setup(vector<Data>& data_t, int b, int e, int x) {
    if (b + 1 == e) {
      tree[x] = data_t[b];
    } else {
      int mid = (b + e)/2;
      Data left = setup(data_t, b, mid, 2*x);
      Data right = setup(data_t, mid, e, 2*x+1);
      tree[x] = combine(left, right);
    }
    return tree[x];
  }

  void setup(vector<Data>& data_t) {
    setup(data_t, 0, size, 1);
  }

  segment_tree_lazy(vector<Data>& data_t, Data un, Data (*c)(Data, Data), Update id, Update (*cu)(Update, Update), Data (*ap)(Data, Update)) {
    size = data_t.size();
    combine = c;
    combine_u = cu;
    apply = ap;
    unity = un;
    identity = id;
    tree = vector<Data>(size*5, unity);
    updates = vector<Update>(size*5, identity);
    setup(data_t);
  }

  void apply_at(int x, Update update) {
    //cout << "apply_at(" << x << ", " << update << ");\n";
    tree[x] = apply(tree[x], update);
    updates[x] = combine_u(updates[x], update);
  }

  void propagate(int x) {
    //cout << "propagate("<<x<<")\n";
    apply_at(2*x, updates[x]);
    apply_at(2*x+1, updates[x]);
    updates[x] = identity;
    //cout << "new updates["<<x<<": " << updates[x] << "\n";
  }

  Data get(int l, int r, int b, int e, int x) {
    //cout << "get(l="<<l<<", r="<<r<<", b="<<b<<", e="<<e<<", x="<<x << "\n";
    if (l >= e || r <= b) return unity;
    //if (b + 1 == e && l <= b && r > b) return tree[x];
    if (l <= b && e <= r) return tree[x];
    propagate(x);
    int mid = (b + e)/2;
    Data left = get(l, r, b, mid, 2*x);
    Data right = get(l, r, mid, e, 2*x+1);
    return combine(left, right);
  }

  void update(int l, int r, Update upd, int b, int e, int x) {
    //cout << "update(l=" << l << ", r=" << r << ", upd=" << upd << ", b=" << b << ", e=" << e << ", x=" << x << ");" << endl;
    if (l >= e || r <= b) return;
    if (l <= b && e <= r) {
      apply_at(x, upd);
      return;
    }
    propagate(x);
    int mid = (b + e)/2;
    update(l, r, upd, b, mid, 2*x);
    update(l, r, upd, mid, e, 2*x+1);
    tree[x] = combine(tree[2*x], tree[2*x+1]);
  }

  Data get(int l, int r) {
    return get(l, r, 0, size, 1);
  }

  void update(int l, int r, Update upd) {
    update(l, r, upd, 0, size, 1);
  }
};

struct data_t {
  int f, s, fs, sf;
  data_t(int f, int s, int fs, int sf) : f(f), s(s), fs(fs), sf(sf) {}
  data_t() : f(0), s(0), fs(0), sf(0) {}
};

data_t combine(data_t l, data_t r) {
  data_t res = data_t();
  res.f = l.f + r.f;
  res.s = l.s + r.s;
  res.fs = max(l.f + r.s, max(l.f + r.fs, l.fs + r.s));
  res.sf = max(l.s + r.f, max(l.s + r.sf, l.sf + r.f));
  return res;
}

bool combine_u(bool a, bool b) {
  return a ^ b;
}

data_t apply(data_t d, bool u) {
  if (u) {
    return data_t(d.s, d.f, d.sf, d.fs);
  }
  return d;
}

data_t unity(0, 0, 0, 0);
bool identity = false;

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  string s; int q, n;
  cin >> n >> q >> s;

  vector<data_t> a;
  for (char c : s) {
    data_t data(c == '4', c == '7', 1, 1);
    a.push_back(data);
  }
  auto tree = segment_tree_lazy<data_t, bool>(a, unity, combine, identity, combine_u, apply);

  while(q--) {
    string s;
    cin >> s;
    if (s == "switch") {
      int l, r; cin >> l >> r;
      tree.update(l-1, r, true);
    } else {
      cout << tree.get(0, a.size()).fs << "\n";
    }
  }
}


#include<bits/stdc++.h>

using namespace std;

#define int long long

template <class Data, class Update>
struct segment_tree_lazy {

  vector<Data> tree;
  vector<Update> updates;
  int size;

  Data (*combine)(Data, Data);
  Update (*combine_u)(Update, Update);
  Data (*apply)(Data, Update);
  Data unity;
  Update identity;

  Data setup(vector<Data>& data_t, int b, int e, int x) {
    if (b + 1 == e) {
      tree[x] = data_t[b];
    } else {
      int mid = (b + e)/2;
      Data left = setup(data_t, b, mid, 2*x);
      Data right = setup(data_t, mid, e, 2*x+1);
      tree[x] = combine(left, right);
    }
    return tree[x];
  }

  void setup(vector<Data>& data_t) {
    setup(data_t, 0, size, 1);
  }

  segment_tree_lazy(vector<Data>& data_t, Data un, Data (*c)(Data, Data), Update id, Update (*cu)(Update, Update), Data (*ap)(Data, Update)) {
    size = data_t.size();
    combine = c;
    combine_u = cu;
    apply = ap;
    unity = un;
    identity = id;
    tree = vector<Data>(size*5, unity);
    updates = vector<Update>(size*5, identity);
    setup(data_t);
  }

  void apply_at(int x, Update update) {
    //cout << "apply_at(" << x << ", " << update << ");\n";
    tree[x] = apply(tree[x], update);
    updates[x] = combine_u(updates[x], update);
  }

  void propagate(int x) {
    //cout << "propagate("<<x<<")\n";
    apply_at(2*x, updates[x]);
    apply_at(2*x+1, updates[x]);
    updates[x] = identity;
    //cout << "new updates["<<x<<": " << updates[x] << "\n";
  }

  Data get(int l, int r, int b, int e, int x) {
    //cout << "get(l="<<l<<", r="<<r<<", b="<<b<<", e="<<e<<", x="<<x << "\n";
    if (l >= e || r <= b) return unity;
    //if (b + 1 == e && l <= b && r > b) return tree[x];
    if (l <= b && e <= r) return tree[x];
    propagate(x);
    int mid = (b + e)/2;
    Data left = get(l, r, b, mid, 2*x);
    Data right = get(l, r, mid, e, 2*x+1);
    return combine(left, right);
  }

  void update(int l, int r, Update upd, int b, int e, int x) {
    //cout << "update(l=" << l << ", r=" << r << ", upd=" << upd << ", b=" << b << ", e=" << e << ", x=" << x << ");" << endl;
    if (l >= e || r <= b) return;
    if (l <= b && e <= r) {
      apply_at(x, upd);
      return;
    }
    propagate(x);
    int mid = (b + e)/2;
    update(l, r, upd, b, mid, 2*x);
    update(l, r, upd, mid, e, 2*x+1);
    tree[x] = combine(tree[2*x], tree[2*x+1]);
  }

  Data get(int l, int r) {
    return get(l, r, 0, size, 1);
  }

  void update(int l, int r, Update upd) {
    update(l, r, upd, 0, size, 1);
  }
};

struct data_t {
  int f, s, fs, sf;
  data_t(int f, int s, int fs, int sf) : f(f), s(s), fs(fs), sf(sf) {}
  data_t() : f(0), s(0), fs(0), sf(0) {}
};

data_t combine(data_t l, data_t r) {
  data_t res = data_t();
  res.f = l.f + r.f;
  res.s = l.s + r.s;
  res.fs = max(l.f + r.s, max(l.f + r.fs, l.fs + r.s));
  res.sf = max(l.s + r.f, max(l.s + r.sf, l.sf + r.f));
  return res;
}

bool combine_u(bool a, bool b) {
  return a ^ b;
}

data_t apply(data_t d, bool u) {
  if (u) {
    return data_t(d.s, d.f, d.sf, d.fs);
  }
  return d;
}

data_t unity(0, 0, 0, 0);
bool identity = false;

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  string s; int q, n;
  cin >> n >> q >> s;

  vector<data_t> a;
  for (char c : s) {
    data_t data(c == '4', c == '7', 1, 1);
    a.push_back(data);
  }
  auto tree = segment_tree_lazy<data_t, bool>(a, unity, combine, identity, combine_u, apply);

  while(q--) {
    string s;
    cin >> s;
    if (s == "switch") {
      int l, r; cin >> l >> r;
      tree.update(l-1, r, true);
    } else {
      //cout << "i f s fs sf\n";
      cout << tree.get(0, a.size()).fs << "\n";
    }
  }
}


#include<bits/stdc++.h>

using namespace std;

#define int long long

template <class Data, class Update>
struct segment_tree_lazy {

  vector<Data> tree;
  vector<Update> updates;
  int size;

  Data (*combine)(Data&, Data&);
  Update (*combine_u)(Update, Update);
  Data (*apply)(Data&, Update);
  Data unity;
  Update identity;

  Data setup(vector<Data>& data_t, int b, int e, int x) {
    if (b + 1 == e) {
      tree[x] = data_t[b];
    } else {
      int mid = (b + e)/2;
      Data left = setup(data_t, b, mid, 2*x);
      Data right = setup(data_t, mid, e, 2*x+1);
      tree[x] = combine(left, right);
    }
    return tree[x];
  }

  void setup(vector<Data>& data_t) {
    setup(data_t, 0, size, 1);
  }

  segment_tree_lazy(vector<Data>& data_t, Data un, Data (*c)(Data&, Data&), Update id, Update (*cu)(Update, Update), Data (*ap)(Data&, Update)) {
    size = data_t.size();
    combine = c;
    combine_u = cu;
    apply = ap;
    unity = un;
    identity = id;
    tree = vector<Data>(size*5, unity);
    updates = vector<Update>(size*5, identity);
    setup(data_t);
  }

  void apply_at(int x, Update update) {
    //cout << "apply_at(" << x << ", " << update << ");\n";
    tree[x] = apply(tree[x], update);
    updates[x] = combine_u(updates[x], update);
  }

  void propagate(int x) {
    //cout << "propagate("<<x<<")\n";
    apply_at(2*x, updates[x]);
    apply_at(2*x+1, updates[x]);
    updates[x] = identity;
    //cout << "new updates["<<x<<": " << updates[x] << "\n";
  }

  Data get(int l, int r, int b, int e, int x) {
    //cout << "get(l="<<l<<", r="<<r<<", b="<<b<<", e="<<e<<", x="<<x << "\n";
    if (l >= e || r <= b) return unity;
    //if (b + 1 == e && l <= b && r > b) return tree[x];
    if (l <= b && e <= r) return tree[x];
    propagate(x);
    int mid = (b + e)/2;
    Data left = get(l, r, b, mid, 2*x);
    Data right = get(l, r, mid, e, 2*x+1);
    return combine(left, right);
  }

  void update(int l, int r, Update upd, int b, int e, int x) {
    //cout << "update(l=" << l << ", r=" << r << ", upd=" << upd << ", b=" << b << ", e=" << e << ", x=" << x << ");" << endl;
    if (l >= e || r <= b) return;
    if (l <= b && e <= r) {
      apply_at(x, upd);
      return;
    }
    propagate(x);
    int mid = (b + e)/2;
    update(l, r, upd, b, mid, 2*x);
    update(l, r, upd, mid, e, 2*x+1);
    tree[x] = combine(tree[2*x], tree[2*x+1]);
  }

  Data get(int l, int r) {
    return get(l, r, 0, size, 1);
  }

  void update(int l, int r, Update upd) {
    update(l, r, upd, 0, size, 1);
  }
};

struct data_t {
  int f, s, fs, sf;
  data_t(int f, int s, int fs, int sf) : f(f), s(s), fs(fs), sf(sf) {}
  data_t() : f(0), s(0), fs(0), sf(0) {}
};

data_t combine(data_t& l, data_t& r) {
  data_t res = data_t();
  res.f = l.f + r.f;
  res.s = l.s + r.s;
  res.fs = max(l.f + r.s, max(l.f + r.fs, l.fs + r.s));
  res.sf = max(l.s + r.f, max(l.s + r.sf, l.sf + r.f));
  return res;
}

bool combine_u(bool a, bool b) {
  return a ^ b;
}

data_t apply(data_t& d, bool u) {
  if (u) {
    return data_t(d.s, d.f, d.sf, d.fs);
  }
  return d;
}

data_t unity(0, 0, 0, 0);
bool identity = false;

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  string s; int q, n;
  cin >> n >> q >> s;

  vector<data_t> a;
  for (char c : s) {
    data_t data(c == '4', c == '7', 1, 1);
    a.push_back(data);
  }
  auto tree = segment_tree_lazy<data_t, bool>(a, unity, combine, identity, combine_u, apply);

  while(q--) {
    string s;
    cin >> s;
    if (s == "switch") {
      int l, r; cin >> l >> r;
      tree.update(l-1, r, true);
    } else {
      cout << tree.get(0, a.size()).fs << "\n";
    }
  }
}


#include<bits/stdc++.h>

using namespace std;

#define int long long

template <class Data, class Update>
struct segment_tree_lazy {

  vector<Data> tree;
  vector<Update> updates;
  int size;

  Data (*combine)(Data, Data);
  Update (*combine_u)(Update, Update);
  Data (*apply)(Data, Update);
  Data unity;
  Update identity;

  Data setup(vector<Data>& data_t, int b, int e, int x) {
    if (b + 1 == e) {
      tree[x] = data_t[b];
    } else {
      int mid = (b + e)/2;
      Data left = setup(data_t, b, mid, 2*x);
      Data right = setup(data_t, mid, e, 2*x+1);
      tree[x] = combine(left, right);
    }
    return tree[x];
  }

  void setup(vector<Data>& data_t) {
    setup(data_t, 0, size, 1);
  }

  segment_tree_lazy(vector<Data>& data_t, Data un, Data (*c)(Data, Data), Update id, Update (*cu)(Update, Update), Data (*ap)(Data, Update)) {
    size = data_t.size();
    combine = c;
    combine_u = cu;
    apply = ap;
    unity = un;
    identity = id;
    tree = vector<Data>(size*5, unity);
    updates = vector<Update>(size*5, identity);
    setup(data_t);
  }

  void apply_at(int x, Update update) {
    //cout << "apply_at(" << x << ", " << update << ");\n";
    tree[x] = apply(tree[x], update);
    updates[x] = combine_u(updates[x], update);
  }

  void propagate(int x) {
    //cout << "propagate("<<x<<")\n";
    apply_at(2*x, updates[x]);
    apply_at(2*x+1, updates[x]);
    updates[x] = identity;
    //cout << "new updates["<<x<<": " << updates[x] << "\n";
  }

  Data get(int l, int r, int b, int e, int x) {
    if (l >= e || r <= b) return unity;
    //if (b + 1 == e && l <= b && r > b) return tree[x];
    if (l <= b && e <= r) return tree[x];
    propagate(x);
    int mid = (b + e)/2;
    Data left = get(l, r, b, mid, 2*x);
    Data right = get(l, r, mid, e, 2*x+1);
    return combine(left, right);
  }

  void update(int l, int r, Update upd, int b, int e, int x) {
    //cout << "update(l=" << l << ", r=" << r << ", upd=" << upd << ", b=" << b << ", e=" << e << ", x=" << x << ");" << endl;
    if (l >= e || r <= b) return;
    if (l <= b && e <= r) {
      apply_at(x, upd);
      return;
    }
    propagate(x);
    int mid = (b + e)/2;
    update(l, r, upd, b, mid, 2*x);
    update(l, r, upd, mid, e, 2*x+1);
    tree[x] = combine(tree[2*x], tree[2*x+1]);
  }

  Data get(int l, int r) {
    return get(l, r, 0, size, 1);
  }

  void update(int l, int r, Update upd) {
    update(l, r, upd, 0, size, 1);
  }
};

struct data_t {
  int f, s, fs, sf;
  data_t(int f, int s, int fs, int sf) : f(f), s(s), fs(fs), sf(sf) {}
  data_t() : f(0), s(0), fs(0), sf(0) {}
};

data_t combine(data_t l, data_t r) {
  data_t res = data_t();
  res.f = l.f + r.f;
  res.s = l.s + r.s;
  res.fs = max(l.f + r.s, max(l.f + r.fs, l.fs + r.s));
  res.sf = max(l.s + r.f, max(l.s + r.sf, l.sf + r.f));
  return res;
}

bool combine_u(bool a, bool b) {
  return a ^ b;
}

data_t apply(data_t d, bool u) {
  if (u) {
    return data_t(d.s, d.f, d.sf, d.fs);
  }
  return d;
}

data_t unity(0, 0, 0, 0);
bool identity = false;

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  string s; int q, n;
  cin >> n >> q >> s;

  vector<data_t> a;
  for (char c : s) {
    data_t data(c == '4', c == '7', 1, 1);
    a.push_back(data);
  }
  auto tree = segment_tree_lazy<data_t, bool>(a, unity, combine, identity, combine_u, apply);

  while(q--) {
    string s;
    cin >> s;
    if (s == "switch") {
      int l, r; cin >> l >> r;
      tree.update(l-1, r, true);
    } else {
      cout << tree.get(0, s.size()).fs << "\n";
    }
  }
}


#include<bits/stdc++.h>

using namespace std;

#define int long long

template <class Data, class Update>
struct segment_tree_lazy {

  vector<Data> tree;
  vector<Update> updates;
  int size;

  Data (*combine)(Data, Data);
  Update (*combine_u)(Update, Update);
  Data (*apply)(Data, Update);
  Data unity;
  Update identity;

  Data setup(vector<Data>& data_t, int b, int e, int x) {
    if (b + 1 == e) {
      tree[x] = data_t[b];
    } else {
      int mid = (b + e)/2;
      Data left = setup(data_t, b, mid, 2*x);
      Data right = setup(data_t, mid, e, 2*x+1);
      tree[x] = combine(left, right);
    }
    return tree[x];
  }

  void setup(vector<Data>& data_t) {
    setup(data_t, 0, size, 1);
  }

  segment_tree_lazy(vector<Data>& data_t, Data un, Data (*c)(Data, Data), Update id, Update (*cu)(Update, Update), Data (*ap)(Data, Update)) {
    size = data_t.size();
    combine = c;
    combine_u = cu;
    apply = ap;
    unity = un;
    identity = id;
    tree = vector<Data>(size*5, unity);
    updates = vector<Update>(size*5, identity);
    setup(data_t);
  }

  void apply_at(int x, Update update) {
    //cout << "apply_at(" << x << ", " << update << ");\n";
    tree[x] = apply(tree[x], update);
    updates[x] = combine_u(updates[x], update);
  }

  void propagate(int x) {
    //cout << "propagate("<<x<<")\n";
    apply_at(2*x, updates[x]);
    apply_at(2*x+1, updates[x]);
    updates[x] = identity;
    //cout << "new updates["<<x<<": " << updates[x] << "\n";
  }

  Data get(int l, int r, int b, int e, int x) {
    //cout << "get(l="<<l<<", r="<<r<<", b="<<b<<", e="<<e<<", x="<<x << "\n";
    if (l >= e || r <= b) return unity;
    //if (b + 1 == e && l <= b && r > b) return tree[x];
    if (l <= b && e <= r) return tree[x];
    propagate(x);
    int mid = (b + e)/2;
    Data left = get(l, r, b, mid, 2*x);
    Data right = get(l, r, mid, e, 2*x+1);
    return combine(left, right);
  }

  void update(int l, int r, Update upd, int b, int e, int x) {
    //cout << "update(l=" << l << ", r=" << r << ", upd=" << upd << ", b=" << b << ", e=" << e << ", x=" << x << ");" << endl;
    if (l >= e || r <= b) return;
    if (l <= b && e <= r) {
      apply_at(x, upd);
      return;
    }
    propagate(x);
    int mid = (b + e)/2;
    update(l, r, upd, b, mid, 2*x);
    update(l, r, upd, mid, e, 2*x+1);
    tree[x] = combine(tree[2*x], tree[2*x+1]);
  }

  Data get(int l, int r) {
    return get(l, r, 0, size, 1);
  }

  void update(int l, int r, Update upd) {
    update(l, r, upd, 0, size, 1);
  }
};

struct data_t {
  int f, s, fs, sf;
  data_t(int f, int s, int fs, int sf) : f(f), s(s), fs(fs), sf(sf) {}
  data_t() : f(0), s(0), fs(0), sf(0) {}
};

data_t combine(data_t l, data_t r) {
  data_t res = data_t();
  res.f = l.f + r.f;
  res.s = l.s + r.s;
  res.fs = max(l.f + r.s, max(l.f + r.fs, l.fs + r.s));
  res.sf = max(l.s + r.f, max(l.s + r.sf, l.sf + r.f));
  return res;
}

bool combine_u(bool a, bool b) {
  return a ^ b;
}

data_t apply(data_t d, bool u) {
  if (u) {
    return data_t(d.s, d.f, d.sf, d.fs);
  }
  return d;
}

data_t unity(0, 0, 0, 0);
bool identity = false;

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  string s; int q, n;
  cin >> n >> q >> s;

  vector<data_t> a;
  for (char c : s) {
    data_t data(c == '4', c == '7', 1, 1);
    a.push_back(data);
  }
  auto tree = segment_tree_lazy<data_t, bool>(a, unity, combine, identity, combine_u, apply);

  while(q--) {
    string s;
    cin >> s;
    if (s == "switch") {
      int l, r; cin >> l >> r;
      tree.update(l-1, r, true);
    } else {
      //cout << "i f s fs sf\n";
      for (int i = 0; i < tree.tree.size(); i++) {
        auto n = tree.tree[i];
        //cout << i << " " << n.f << " " << n.s << " " << n.fs << " " << n.sf << "\n";
      }
      cout << tree.get(0, a.size()).fs << "\n";
    }
  }
}


#include <bits/stdc++.h>

typedef int ll;

typedef long double ld;

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("-O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;

#define fi first
#define se second
#define sz(x) (ll)(x).size()
#define pll pair<ll,ll >
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define endln '\n'
#define cont continue
#define sqr(x) (x) * (x)
#define sz(x) (x).size()
//#define min(a,b) ((a) < (b)? (a) : (b))
//#define max(a,b) ((a) > (b)? (a) : (b))

const ll MaxN = 1e6 + 100;
const ll LogN = 20;
const ll Inf = 1e9;
double eps = 1e-7;
ll md = 998244353;
ll dx[4] = { 1,0,0,-1 };
ll dy[4] = { 0,1,-1,0 };

ll Mt[MaxN];
ll T4[MaxN * 4];
ll T7[MaxN * 4];
ll T47[MaxN * 4];
ll T74[MaxN * 4];

ll Mn[MaxN * 4];

void Build(ll l, ll r, ll id) {
	if (l == r) {
		if (Mt[l] == 4) {
			T4[id] = 1;
		}
		else {
			T7[id] = 1;
		}
		T74[id] = 1;
		T47[id] = 1;
	}
	else {
		ll mid = (l + r) / 2;
		Build(l, mid, id * 2 +1);
		Build(mid + 1, r, id * 2 +2);
		T4[id] = T4[id * 2 + 1] + T4[id * 2 + 2];
		T7[id] = T7[id * 2 + 1] + T7[id * 2 + 2];
		T47[id] = max({T47[id*2+1] + T7[id*2+2], T4[id*2+1] + T47[id*2+2], T4[id*2+1] + T7[id*2+2]});
		T74[id] = max({ T74[id * 2 + 1] + T4[id * 2 + 2], T7[id * 2 + 1] + T74[id * 2 + 2], T7[id * 2 + 1] + T4[id * 2 + 2] });

	}
}
void push(ll v, bool f) {
	Mn[v] = 0;
	if (f) {
		Mn[v * 2 + 1] ^= 1;
		Mn[v * 2 + 2] ^= 1;
	}
	swap(T4[v], T7[v]);
	swap(T47[v], T74[v]);
}

void edit(ll l, ll r, ll x, ll y, ll id) {
	if (Mn[id]) {
		Mn[id] = 0;
		if (l != r) {
			Mn[id * 2 + 1] ^= 1;
			Mn[id * 2 + 2] ^= 1;
		}
		swap(T4[id], T7[id]);
		swap(T47[id], T74[id]);
	}
	if (l == x && y == r) {
		if (l != r) {
			Mn[id * 2 + 1] ^= 1;
			Mn[id * 2 + 2] ^= 1;
		}
		swap(T4[id], T7[id]);
		swap(T47[id], T74[id]);
	}
	else {
		ll mid = (l + r) / 2;
		if (y <= mid) edit(l, mid, x, y, id * 2 + 1);
		else if (x >= mid + 1) edit(mid + 1, r, x, y, id * 2 + 2);
		else {
			edit(l, mid, x, mid, id * 2 + 1);
			edit(mid + 1, r, mid + 1, y, id * 2 + 2);
		}
		if (Mn[id * 2 + 1]  ) push(id * 2 + 1, l != r - 1);
		if (Mn[id * 2 + 2]  ) push(id * 2 + 2, l != r - 1);
		T4[id] = T4[id * 2 + 1] + T4[id * 2 + 2];
		T7[id] = T7[id * 2 + 1] + T7[id * 2 + 2];
		T47[id] = max({ T47[id * 2 + 1] + T7[id * 2 + 2], T4[id * 2 + 1] + T47[id * 2 + 2], T4[id * 2 + 1] + T7[id * 2 + 2] });
		T74[id] = max({ T74[id * 2 + 1] + T4[id * 2 + 2], T7[id * 2 + 1] + T74[id * 2 + 2], T7[id * 2 + 1] + T4[id * 2 + 2] });

	}
}

int main()
{
#ifdef LOCAL
	ifstream cin("input.txt");
	ofstream cout("output.txt");
#else
	//ifstream cin("puzzle.dat");
	//ofstream cout("puzzle.sol");
#endif
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//cout << fixed << setprecision(15);

	ll N, Q;
	cin >> N >> Q;
	string s;
	cin >> s;
	for (int i = 0;i < N;i++) {
		Mt[i] = s[i] - '0';
	}
	Build(0, N - 1, 0);

	while (Q--) {
		string s;
		cin >> s;
		if (s == "count") {
			cout << T47[0] << endln;
		}
		else {
			ll l, r;
			cin >> l >> r;
			l--;
			r--;
			edit(0, N - 1, l, r, 0);
		}
	}

	return 0;

}


#include <bits/stdc++.h>

typedef int ll;

typedef long double ld;

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("-O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;

#define fi first
#define se second
#define sz(x) (ll)(x).size()
#define pll pair<ll,ll >
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define endln '\n'
#define cont continue
#define sqr(x) (x) * (x)
#define sz(x) (x).size()
//#define min(a,b) ((a) < (b)? (a) : (b))
//#define max(a,b) ((a) > (b)? (a) : (b))

const ll MaxN = 1e6 + 100;
const ll LogN = 20;
const ll Inf = 1e9;
double eps = 1e-7;
ll md = 998244353;
ll dx[4] = { 1,0,0,-1 };
ll dy[4] = { 0,1,-1,0 };

ll Mt[MaxN];
ll T4[MaxN * 4];
ll T7[MaxN * 4];
ll T47[MaxN * 4];
ll T74[MaxN * 4];

ll Mn[MaxN * 4];

void Build(ll l, ll r, ll id) {
	if (l == r) {
		if (Mt[l] == 4) {
			T4[id] = 1;
		}
		else {
			T7[id] = 1;
		}
		T74[id] = 1;
		T47[id] = 1;
	}
	else {
		ll mid = (l + r) / 2;
		Build(l, mid, id * 2 +1);
		Build(mid + 1, r, id * 2 +2);
		T4[id] = T4[id * 2 + 1] + T4[id * 2 + 2];
		T7[id] = T7[id * 2 + 1] + T7[id * 2 + 2];
		T47[id] = max({T47[id*2+1] + T7[id*2+2], T4[id*2+1] + T47[id*2+2], T4[id*2+1] + T7[id*2+2]});
		T74[id] = max({ T74[id * 2 + 1] + T4[id * 2 + 2], T7[id * 2 + 1] + T74[id * 2 + 2], T7[id * 2 + 1] + T4[id * 2 + 2] });

	}
}
void push(ll v) {
	Mn[v] = 0;
	Mn[v* 2 + 1] ^= 1;
	Mn[v * 2 + 2] ^= 1;
	swap(T4[v], T7[v]);
	swap(T47[v], T74[v]);
}

void edit(ll l, ll r, ll x, ll y, ll id) {
	if (Mn[id]) {
		Mn[id] = 0;
		Mn[id * 2 + 1] ^= 1;
		Mn[id * 2 + 2] ^= 1;
		swap(T4[id], T7[id]);
		swap(T47[id], T74[id]);
	}
	if (l == x && y == r) {
		if (l != r) {
			Mn[id * 2 + 1] ^= 1;
			Mn[id * 2 + 2] ^= 1;
		}
		swap(T4[id], T7[id]);
		swap(T47[id], T74[id]);
	}
	else {
		ll mid = (l + r) / 2;
		if (y <= mid) edit(l, mid, x, y, id * 2 + 1);
		else if (x >= mid + 1) edit(mid + 1, r, x, y, id * 2 + 2);
		else {
			edit(l, mid, x, mid, id * 2 + 1);
			edit(mid + 1, r, mid + 1, y, id * 2 + 2);
		}
		if (Mn[id * 2 + 1] && l != r-1) push(id * 2 + 1);
		if (Mn[id * 2 + 2] && l != r - 1) push(id * 2 + 2);
		T4[id] = T4[id * 2 + 1] + T4[id * 2 + 2];
		T7[id] = T7[id * 2 + 1] + T7[id * 2 + 2];
		T47[id] = max({ T47[id * 2 + 1] + T7[id * 2 + 2], T4[id * 2 + 1] + T47[id * 2 + 2], T4[id * 2 + 1] + T7[id * 2 + 2] });
		T74[id] = max({ T74[id * 2 + 1] + T4[id * 2 + 2], T7[id * 2 + 1] + T74[id * 2 + 2], T7[id * 2 + 1] + T4[id * 2 + 2] });

	}
}

int main()
{
#ifdef LOCAL
	ifstream cin("input.txt");
	ofstream cout("output.txt");
#else
	//ifstream cin("puzzle.dat");
	//ofstream cout("puzzle.sol");
#endif
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//cout << fixed << setprecision(15);

	ll N, Q;
	cin >> N >> Q;
	string s;
	cin >> s;
	for (int i = 0;i < N;i++) {
		Mt[i] = s[i] - '0';
	}
	Build(0, N - 1, 0);

	while (Q--) {
		string s;
		cin >> s;
		if (s == "count") {
			cout << T47[0] << endln;
		}
		else {
			ll l, r;
			cin >> l >> r;
			l--;
			r--;
			edit(0, N - 1, l, r, 0);
		}
	}

	return 0;

}


#include <bits/stdc++.h>

typedef int ll;

typedef long double ld;

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("-O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;

#define fi first
#define se second
#define sz(x) (ll)(x).size()
#define pll pair<ll,ll >
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define endln '\n'
#define cont continue
#define sqr(x) (x) * (x)
#define sz(x) (x).size()
//#define min(a,b) ((a) < (b)? (a) : (b))
//#define max(a,b) ((a) > (b)? (a) : (b))

const ll MaxN = 1e6 + 100;
const ll LogN = 20;
const ll Inf = 1e9;
double eps = 1e-7;
ll md = 998244353;
ll dx[4] = { 1,0,0,-1 };
ll dy[4] = { 0,1,-1,0 };

ll Mt[MaxN];
ll T4[MaxN * 4];
ll T7[MaxN * 4];
ll T47[MaxN * 4];
ll T74[MaxN * 4];

ll Mn[MaxN * 4];

void Build(ll l, ll r, ll id) {
	if (l == r) {
		if (Mt[l] == 4) {
			T4[id] = 1;
		}
		else {
			T7[id] = 1;
		}
		T74[id] = 1;
		T47[id] = 1;
	}
	else {
		ll mid = (l + r) / 2;
		Build(l, mid, id * 2 +1);
		Build(mid + 1, r, id * 2 +2);
		T4[id] = T4[id * 2 + 1] + T4[id * 2 + 2];
		T7[id] = T7[id * 2 + 1] + T7[id * 2 + 2];
		T47[id] = max({T47[id*2+1] + T7[id*2+2], T4[id*2+1] + T47[id*2+2], T4[id*2+1] + T7[id*2+2]});
		T74[id] = max({ T74[id * 2 + 1] + T4[id * 2 + 2], T7[id * 2 + 1] + T74[id * 2 + 2], T7[id * 2 + 1] + T4[id * 2 + 2] });

	}
}
void push(ll v, bool f) {
	Mn[v] = 0;
	if (f) {
		Mn[v * 2 + 1] ^= 1;
		Mn[v * 2 + 2] ^= 1;
	}
	swap(T4[v], T7[v]);
	swap(T47[v], T74[v]);
}

void edit(ll l, ll r, ll x, ll y, ll id) {
	if (Mn[id]) {
		Mn[id] = 0;
		Mn[id * 2 + 1] ^= 1;
		Mn[id * 2 + 2] ^= 1;
		swap(T4[id], T7[id]);
		swap(T47[id], T74[id]);
	}
	if (l == x && y == r) {
		if (l != r) {
			Mn[id * 2 + 1] ^= 1;
			Mn[id * 2 + 2] ^= 1;
		}
		swap(T4[id], T7[id]);
		swap(T47[id], T74[id]);
	}
	else {
		ll mid = (l + r) / 2;
		if (y <= mid) edit(l, mid, x, y, id * 2 + 1);
		else if (x >= mid + 1) edit(mid + 1, r, x, y, id * 2 + 2);
		else {
			edit(l, mid, x, mid, id * 2 + 1);
			edit(mid + 1, r, mid + 1, y, id * 2 + 2);
		}
		if (Mn[id * 2 + 1]  ) push(id * 2 + 1, l != r - 1);
		if (Mn[id * 2 + 2]  ) push(id * 2 + 2, l != r - 1);
		T4[id] = T4[id * 2 + 1] + T4[id * 2 + 2];
		T7[id] = T7[id * 2 + 1] + T7[id * 2 + 2];
		T47[id] = max({ T47[id * 2 + 1] + T7[id * 2 + 2], T4[id * 2 + 1] + T47[id * 2 + 2], T4[id * 2 + 1] + T7[id * 2 + 2] });
		T74[id] = max({ T74[id * 2 + 1] + T4[id * 2 + 2], T7[id * 2 + 1] + T74[id * 2 + 2], T7[id * 2 + 1] + T4[id * 2 + 2] });

	}
}

int main()
{
#ifdef LOCAL
	ifstream cin("input.txt");
	ofstream cout("output.txt");
#else
	//ifstream cin("puzzle.dat");
	//ofstream cout("puzzle.sol");
#endif
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//cout << fixed << setprecision(15);

	ll N, Q;
	cin >> N >> Q;
	string s;
	cin >> s;
	for (int i = 0;i < N;i++) {
		Mt[i] = s[i] - '0';
	}
	Build(0, N - 1, 0);

	while (Q--) {
		string s;
		cin >> s;
		if (s == "count") {
			cout << T47[0] << endln;
		}
		else {
			ll l, r;
			cin >> l >> r;
			l--;
			r--;
			edit(0, N - 1, l, r, 0);
		}
	}

	return 0;

}


#include <bits/stdc++.h>

typedef int ll;

typedef long double ld;

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("-O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;

#define fi first
#define se second
#define sz(x) (ll)(x).size()
#define pll pair<ll,ll >
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define endln '\n'
#define cont continue
#define sqr(x) (x) * (x)
#define sz(x) (x).size()
//#define min(a,b) ((a) < (b)? (a) : (b))
//#define max(a,b) ((a) > (b)? (a) : (b))

const ll MaxN = 1e6 + 100;
const ll LogN = 20;
const ll Inf = 1e9;
double eps = 1e-7;
ll md = 998244353;
ll dx[4] = { 1,0,0,-1 };
ll dy[4] = { 0,1,-1,0 };

ll Mt[MaxN];
ll T4[MaxN * 4];
ll T7[MaxN * 4];
ll T47[MaxN * 4];
ll T74[MaxN * 4];

ll Mn[MaxN * 4];

void Build(ll l, ll r, ll id) {
	if (l == r) {
		if (Mt[l] == 4) {
			T4[id] = 1;
		}
		else {
			T7[id] = 1;
		}
		T74[id] = 1;
		T47[id] = 1;
	}
	else {
		ll mid = (l + r) / 2;
		Build(l, mid, id * 2 +1);
		Build(mid + 1, r, id * 2 +2);
		T4[id] = T4[id * 2 + 1] + T4[id * 2 + 2];
		T7[id] = T7[id * 2 + 1] + T7[id * 2 + 2];
		T47[id] = max({T47[id*2+1] + T7[id*2+2], T4[id*2+1] + T47[id*2+2], T4[id*2+1] + T7[id*2+2]});
		T74[id] = max({ T74[id * 2 + 1] + T4[id * 2 + 2], T7[id * 2 + 1] + T74[id * 2 + 2], T7[id * 2 + 1] + T4[id * 2 + 2] });

	}
}
void push(ll v) {
	Mn[v] = 0;
	Mn[v* 2 + 1] ^= 1;
	Mn[v * 2 + 2] ^= 1;
	swap(T4[v], T7[v]);
	swap(T47[v], T74[v]);
}

void edit(ll l, ll r, ll x, ll y, ll id) {
	if (Mn[id]) {
		Mn[id] = 0;
		Mn[id * 2 + 1] ^= 1;
		Mn[id * 2 + 2] ^= 1;
		swap(T4[id], T7[id]);
		swap(T47[id], T74[id]);
	}
	if (l == x && y == r) {
		Mn[id*2 +1] ^= 1;
		Mn[id * 2 + 2] ^= 1;
		swap(T4[id], T7[id]);
		swap(T47[id], T74[id]);
	}
	else {
		ll mid = (l + r) / 2;
		if (y <= mid) edit(l, mid, x, y, id * 2 + 1);
		else if (x >= mid + 1) edit(mid + 1, r, x, y, id * 2 + 2);
		else {
			edit(l, mid, x, mid, id * 2 + 1);
			edit(mid + 1, r, mid + 1, y, id * 2 + 2);
		}
		if (Mn[id * 2 + 1]) push(id * 2 + 1);
		if (Mn[id * 2 + 2]) push(id * 2 + 2);
		T4[id] = T4[id * 2 + 1] + T4[id * 2 + 2];
		T7[id] = T7[id * 2 + 1] + T7[id * 2 + 2];
		T47[id] = max({ T47[id * 2 + 1] + T7[id * 2 + 2], T4[id * 2 + 1] + T47[id * 2 + 2], T4[id * 2 + 1] + T7[id * 2 + 2] });
		T74[id] = max({ T74[id * 2 + 1] + T4[id * 2 + 2], T7[id * 2 + 1] + T74[id * 2 + 2], T7[id * 2 + 1] + T4[id * 2 + 2] });

	}
}

int main()
{
#ifdef LOCAL
	ifstream cin("input.txt");
	ofstream cout("output.txt");
#else
	//ifstream cin("puzzle.dat");
	//ofstream cout("puzzle.sol");
#endif
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//cout << fixed << setprecision(15);

	ll N, Q;
	cin >> N >> Q;
	string s;
	cin >> s;
	for (int i = 0;i < N;i++) {
		Mt[i] = s[i] - '0';
	}
	Build(0, N - 1, 0);

	while (Q--) {
		string s;
		cin >> s;
		if (s == "count") {
			cout << T47[0] << endln;
		}
		else {
			ll l, r;
			cin >> l >> r;
			l--;
			r--;
			edit(0, N - 1, l, r, 0);
		}
	}

	return 0;

}


#include <bits/stdc++.h>

typedef int ll;

typedef long double ld;

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("-O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;

#define fi first
#define se second
#define sz(x) (ll)(x).size()
#define pll pair<ll,ll >
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define endln '\n'
#define cont continue
#define sqr(x) (x) * (x)
#define sz(x) (x).size()
//#define min(a,b) ((a) < (b)? (a) : (b))
//#define max(a,b) ((a) > (b)? (a) : (b))

const ll MaxN = 1e6 + 100;
const ll LogN = 20;
const ll Inf = 1e9;
double eps = 1e-7;
ll md = 998244353;
ll dx[4] = { 1,0,0,-1 };
ll dy[4] = { 0,1,-1,0 };

ll Mt[MaxN];
ll T4[MaxN * 4];
ll T7[MaxN * 4];
ll T47[MaxN * 4];
ll T74[MaxN * 4];

ll Mn[MaxN * 4];

void Build(ll l, ll r, ll id) {
	if (l == r) {
		if (Mt[l] == 4) {
			T4[id] = 1;
		}
		else {
			T7[id] = 1;
		}
		T74[id] = 1;
		T47[id] = 1;
	}
	else {
		ll mid = (l + r) / 2;
		Build(l, mid, id * 2 +1);
		Build(mid + 1, r, id * 2 +2);
		T4[id] = T4[id * 2 + 1] + T4[id * 2 + 2];
		T7[id] = T7[id * 2 + 1] + T7[id * 2 + 2];
		T47[id] = max({T47[id*2+1] + T7[id*2+2], T4[id*2+1] + T47[id*2+2], T4[id*2+1] + T7[id*2+2]});
		T74[id] = max({ T74[id * 2 + 1] + T4[id * 2 + 2], T7[id * 2 + 1] + T74[id * 2 + 2], T7[id * 2 + 1] + T4[id * 2 + 2] });

	}
}

void edit(ll l, ll r, ll x, ll y, ll id) {
	if (Mn[id]) {
		Mn[id] = 0;
		Mn[id * 2 + 1] ^= 1;
		Mn[id * 2 + 2] ^= 1;
		swap(T4[id], T7[id]);
		swap(T47[id], T74[id]);
	}
	if (l == x && y == r) {
		Mn[id*2 +1] ^= 1;
		Mn[id * 2 + 2] ^= 1;
		swap(T4[id], T7[id]);
		swap(T47[id], T74[id]);
	}
	else {
		ll mid = (l + r) / 2;
		if (y <= mid) edit(l, mid, x, y, id * 2 + 1);
		else if (x >= mid + 1) edit(mid + 1, r, x, y, id * 2 + 2);
		else {
			edit(l, mid, x, mid, id * 2 + 1);
			edit(mid + 1, r, mid + 1, y, id * 2 + 2);
		}
		T4[id] = T4[id * 2 + 1] + T4[id * 2 + 2];
		T7[id] = T7[id * 2 + 1] + T7[id * 2 + 2];
		T47[id] = max({ T47[id * 2 + 1] + T7[id * 2 + 2], T4[id * 2 + 1] + T47[id * 2 + 2], T4[id * 2 + 1] + T7[id * 2 + 2] });
		T74[id] = max({ T74[id * 2 + 1] + T4[id * 2 + 2], T7[id * 2 + 1] + T74[id * 2 + 2], T7[id * 2 + 1] + T4[id * 2 + 2] });

	}
}

int main()
{
#ifdef LOCAL
	ifstream cin("input.txt");
	ofstream cout("output.txt");
#else
	//ifstream cin("puzzle.dat");
	//ofstream cout("puzzle.sol");
#endif
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//cout << fixed << setprecision(15);

	ll N, Q;
	cin >> N >> Q;
	string s;
	cin >> s;
	for (int i = 0;i < N;i++) {
		Mt[i] = s[i] - '0';
	}
	Build(0, N - 1, 0);

	while (Q--) {
		string s;
		cin >> s;
		if (s == "count") {
			cout << T47[0] << endln;
		}
		else {
			ll l, r;
			cin >> l >> r;
			l--;
			r--;
			edit(0, N - 1, l, r, 0);
		}
	}

	return 0;

}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;

#define FOR(i, a, b) for(ll i=ll(a); i<ll(b); i++)
#define ROF(i, a, b) for(ll i=ll(a); i>=ll(b); i--)
#define pb push_back
#define mp make_pair
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL); //cout.tie(NULL)
#define mem(x, val) memset((x), (val), sizeof(x))
#define MOD 1000000007
#define etr "\n"
#define INF 10E10
const ll MAX = 1000050;

struct Node{
    ll inc, x4s, x7s, dec;
    Node(ll i, ll x, ll y, ll dec) : inc(i), x4s(x), x7s(y), dec(dec){}
    Node(){}
};

ll arr[MAX];
Node t[MAX*4];
bool lzy[MAX*4];
ll n, m;

Node merge(ll nde){
    Node &l = t[2*nde+1], &r = t[2*nde+2];
    return Node(max(l.x4s + r.inc, l.inc + r.x7s), l.x4s + r.x4s, l.x7s + r.x7s, max(l.x7s + r.dec, l.dec + r.x4s));
}
void inv(ll nde){
    t[nde] = Node(t[nde].dec, t[nde].x7s, t[nde].x4s, t[nde].inc);
}

void push(ll nde, bool u){ // update lazy
    if(!lzy[nde]) return;
    inv(nde);
    if(u){
        lzy[nde] = false; return;
    }
    lzy[2*nde+1] ^= lzy[nde];
    lzy[2*nde+2] ^= lzy[nde];
    lzy[nde] = false;
}

void build(ll l, ll r, ll nde){
    if(l == r){
        t[nde] = Node(1, (arr[r] ? 0 : 1), (arr[r] ? 1 : 0), 1);
        return;
    }
    ll m = l + (r-l)/2;
    build(l, m, 2*nde+1), build(m+1, r, 2*nde+2);
    t[nde] = merge(nde);
}

void rupdate(ll l, ll r, ll ql, ll qr, ll nde){ // range update (adition)
    if(l > r) return;
    push(nde, l==r);
    if(ql > r || qr < l) return; // no ovelap
    if(ql <= l && qr >= r){ // total overlap
        lzy[nde] ^= true; push(nde, l == r);
        return;
    }
    ll m = l + (r-l)/2;
    rupdate(l, m, ql, qr, 2*nde+1); rupdate(m+1, r, ql, qr, 2*nde+2);
    t[nde] = merge(nde); // partial ovelap
}

ll query(){
    push(0, 0 == n-1);
    return t[0].inc;
}
void update(ll ql, ll qr){
    rupdate(0, n-1, ql, qr, 0);
}

int main(){
	sync;
    cin >> n >> m;
    string s;
    cin >> s;
    FOR(i, 0, n){
        if(s[i] =='4') arr[i] = 0;
        else arr[i] = 1;
    }

    build(0, n-1, 0);

    FOR(i, 0, m){
        cin >> s;
        if(s[0] == 'c'){//a
            cout << query() << etr;
        }
        else{
            ll a, b;
            cin >> a >> b;
            a--; b--;
            update(a, b);
        }

    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;

#define FOR(i, a, b) for(ll i=ll(a); i<ll(b); i++)
#define ROF(i, a, b) for(ll i=ll(a); i>=ll(b); i--)
#define pb push_back
#define mp make_pair
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL); //cout.tie(NULL)
#define mem(x, val) memset((x), (val), sizeof(x))
#define MOD 1000000007
#define etr "\n"
#define INF 10E10
const ll MAX = 1000050;

struct Node{
    ll inc, x4s, x7s, dec;
    Node(ll i, ll x, ll y, ll dec) : inc(i), x4s(x), x7s(y), dec(dec){}
    Node(){}
};

ll arr[MAX];
Node t[MAX*4];
bool lzy[MAX*4];
ll n, m;

Node merge(ll nde){
    Node &l = t[2*nde+1], &r = t[2*nde+2];
    return Node(max(l.x4s + r.inc, l.inc + r.x7s), l.x4s + r.x4s, l.x7s + r.x7s, max(l.x7s + r.dec, l.dec + r.x4s));
}
void inv(ll nde){
    t[nde] = Node(t[nde].dec, t[nde].x7s, t[nde].x4s, t[nde].inc);
}

void push(ll nde, bool u){ // update lazy
    if(!lzy[nde]) return;
    inv(nde);
    if(u){
        lzy[nde] = false; return;
    }
    lzy[2*nde+1] ^= lzy[nde];
    lzy[2*nde+2] ^= lzy[nde];
    lzy[nde] = false;
}

void build(ll l, ll r, ll nde){
    if(l == r){
        t[nde] = Node(1, (arr[r] ? 0 : 1), (arr[r] ? 1 : 0), 1);
        return;
    }
    ll m = l + (r-l)/2;
    build(l, m, 2*nde+1), build(m+1, r, 2*nde+2);
    t[nde] = merge(nde);
}

void rupdate(ll l, ll r, ll ql, ll qr, ll nde){ // range update (adition)
    if(l > r) return;
    push(nde, l==r);
    if(ql > r || qr < l) return; // no ovelap
    if(ql <= l && qr >= r){ // total overlap
        lzy[nde] ^= true; push(nde, l == r);
        return;
    }
    ll m = l + (r-l)/2;
    rupdate(l, m, ql, qr, 2*nde+1); rupdate(m+1, r, ql, qr, 2*nde+2);
    t[nde] = merge(nde); // partial ovelap
}

ll query(){
    push(0, 0 == n-1);
    return t[0].inc;
}
void update(ll ql, ll qr){
    rupdate(0, n-1, ql, qr, 0);
}

int main(){
	//sync;
    cin >> n >> m;
    string s;
    cin >> s;
    FOR(i, 0, n){
        if(s[i] =='4') arr[i] = 0;
        else arr[i] = 1;
    }

    build(0, n-1, 0);

    FOR(i, 0, m){
        cin >> s;
        if(s[0] == 'c'){
            cout << query() << etr;
        }
        else{
            ll a, b;
            cin >> a >> b;
            a--; b--;
            update(a, b);
        }

    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;

#define FOR(i, a, b) for(ll i=ll(a); i<ll(b); i++)
#define ROF(i, a, b) for(ll i=ll(a); i>=ll(b); i--)
#define pb push_back
#define mp make_pair
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL); //cout.tie(NULL)
#define mem(x, val) memset((x), (val), sizeof(x))
#define MOD 1000000007
#define etr "\n"
#define INF 10E10
const ll MAX = 1000050;

struct Node{
    ll inc, x4s, x7s, dec;
    Node(ll i, ll x, ll y, ll dec) : inc(i), x4s(x), x7s(y), dec(dec){}
    Node(){}
};

ll arr[MAX];
Node t[MAX*4];
bool lzy[MAX*4];
ll n, m;

Node merge(ll nde){
    Node &l = t[2*nde+1], &r = t[2*nde+2];
    return Node(max(l.x4s + r.inc, l.inc + r.x7s), l.x4s + r.x4s, l.x7s + r.x7s, max(l.x7s + r.dec, l.dec + r.x4s));
}
void inv(ll nde){
    t[nde] = Node(t[nde].dec, t[nde].x7s, t[nde].x4s, t[nde].inc);
}

void push(ll nde, bool u){ // update lazy
    if(!lzy[nde]) return;
    inv(nde);
    if(u){
        lzy[nde] = false; return;
    }
    lzy[2*nde+1] ^= lzy[nde];
    lzy[2*nde+2] ^= lzy[nde];
    lzy[nde] = false;
}

void build(ll l, ll r, ll nde){
    if(l == r){
        t[nde] = Node(1, (arr[r] ? 0 : 1), (arr[r] ? 1 : 0), 1);
        return;
    }
    ll m = l + (r-l)/2;
    build(l, m, 2*nde+1), build(m+1, r, 2*nde+2);
    t[nde] = merge(nde);
}

void rupdate(ll l, ll r, ll ql, ll qr, ll nde){ // range update (adition)
    if(l > r) return;
    push(nde, l==r);
    if(ql > r || qr < l) return; // no ovelap
    if(ql <= l && qr >= r){ // total overlap
        lzy[nde] ^= true; push(nde, l == r);
        return;
    }
    ll m = l + (r-l)/2;
    rupdate(l, m, ql, qr, 2*nde+1); rupdate(m+1, r, ql, qr, 2*nde+2);
    t[nde] = merge(nde); // partial ovelap
}

ll query(){
    push(0, 0 == n-1);
    return t[0].inc;
}
void update(ll ql, ll qr){
    rupdate(0, n-1, ql, qr, 0);
}

int main(){
	sync;
    cin >> n >> m;
    string s;
    cin >> s;
    FOR(i, 0, n){
        if(s[i] =='4') arr[i] = 0;
        else arr[i] = 1;
    }

    build(0, n-1, 0);

    FOR(i, 0, m){
        cin >> s;
        if(s[0] == 'c'){
            cout << query() << etr;
        }
        else{
            ll a, b;
            cin >> a >> b;
            a--; b--;
            update(a, b);
        }

    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;

#define FOR(i, a, b) for(ll i=ll(a); i<ll(b); i++)
#define ROF(i, a, b) for(ll i=ll(a); i>=ll(b); i--)
#define pb push_back
#define mp make_pair
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL); //cout.tie(NULL)
#define mem(x, val) memset((x), (val), sizeof(x))
#define MOD 1000000007
#define etr "\n"
#define INF 10E10
const ll MAX = 200050;

struct Node{
    ll inc, x4s, x7s, dec;
    Node(ll i, ll x, ll y, ll dec) : inc(i), x4s(x), x7s(y), dec(dec){}
    Node(){}
};

ll arr[MAX];
Node t[MAX*4];
bool lzy[MAX*4];
ll n, m;

Node merge(ll nde){
    Node &l = t[2*nde+1], &r = t[2*nde+2];
    return Node(max(l.x4s + r.inc, l.inc + r.x7s), l.x4s + r.x4s, l.x7s + r.x7s, max(l.x7s + r.dec, l.dec + r.x4s));
}
void inv(ll nde){
    t[nde] = Node(t[nde].dec, t[nde].x7s, t[nde].x4s, t[nde].inc);
}

void push(ll nde, bool u){ // update lazy
    if(!lzy[nde]) return;
    inv(nde);
    if(u){
        lzy[nde] = false; return;
    }
    lzy[2*nde+1] ^= lzy[nde];
    lzy[2*nde+2] ^= lzy[nde];
    lzy[nde] = false;
}

void build(ll l, ll r, ll nde){
    if(l == r){
        t[nde] = Node(1, (arr[r] ? 0 : 1), (arr[r] ? 1 : 0), 1);
        return;
    }
    ll m = l + (r-l)/2;
    build(l, m, 2*nde+1), build(m+1, r, 2*nde+2);
    t[nde] = merge(nde);
}

void rupdate(ll l, ll r, ll ql, ll qr, ll nde){ // range update (adition)
    if(l > r) return;
    push(nde, l==r);
    if(ql > r || qr < l) return; // no ovelap
    if(ql <= l && qr >= r){ // total overlap
        lzy[nde] ^= true; push(nde, l == r);
        return;
    }
    ll m = l + (r-l)/2;
    rupdate(l, m, ql, qr, 2*nde+1); rupdate(m+1, r, ql, qr, 2*nde+2);
    t[nde] = merge(nde); // partial ovelap
}

ll query(){
    push(0, 0 == n-1);
    return t[0].inc;
}
void update(ll ql, ll qr){
    rupdate(0, n-1, ql, qr, 0);
}

int main(){
	//sync;
    cin >> n >> m;
    string s;
    cin >> s;
    FOR(i, 0, n){
        if(s[i] =='4') arr[i] = 0;
        else arr[i] = 1;
    }

    build(0, n-1, 0);

    FOR(i, 0, m){
        cin >> s;
        if(s[0] == 'c'){
            cout << query() << etr;
        }
        else{
            ll a, b;
            cin >> a >> b;
            a--; b--;
            update(a, b);
        }

    }

    return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define x first
#define y second
#define ld long double
#define ll long long

using namespace std;

struct Nod {
  bool rev;
  int n4, n7, inc, desc;
};

int n, q, x, y;

char s[1000005];
string t;
Nod aint[4000005];

void rev(Nod &a) {
  a.rev ^= 1;
  swap(a.n4, a.n7), swap(a.inc, a.desc);
}

void join(int a, int b, int c) {
  aint[a].n4 = aint[b].n4 + aint[c].n4;
  aint[a].n7 = aint[b].n7 + aint[c].n7;
  aint[a].inc = max(aint[b].inc + aint[c].n7, aint[b].n4 + aint[c].inc);
  aint[a].desc = max(aint[b].desc + aint[c].n4, aint[b].n7 + aint[c].desc);
}

void build(int nod, int st, int dr) {
  if(st > dr)
    return;
  if(st == dr) {
    aint[nod] = {0, (s[st] == '4'), (s[st] == '7'), 1, 1};
    return;
  }
  int mid = (st + dr) >> 1, a = (nod << 1), b = (a | 1);
  build(a, st, mid), build(b, mid + 1, dr);
  join(nod, a, b);
}

void update(int nod, int st, int dr, int l, int r) {
  if(st > dr)
    return;
  if(l <= st && dr <= r) {
    rev(aint[nod]);
    return;
  }
  int mid = (st + dr) >> 1, a = (nod << 1), b = (a | 1);
  if(aint[nod].rev) {
    aint[nod].rev = 0;
    rev(aint[a]), rev(aint[b]);
  }
  update(a, st, mid, l, r), update(b, mid + 1, dr, l, r);
  join(nod, a, b);
}

int main() {
  cin >> n >> q >> (s + 1);
  build(1, 1, n);
  for(; q; q--) {
    cin >> t;
    if(t == "count")
      cout << aint[1].inc << "\n";
    else {
      cin >> x >> y;
      update(1, 1, n, x, y);
    }
  }
  return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define x first
#define y second
#define ld long double
#define ll long long

using namespace std;

struct Nod {
  bool rev;
  int n4, n7, inc, desc;
};

int n, q, x, y;

char s[1000005];
string t;
Nod aint[4000005];

void rev(Nod &a) {
  a.rev ^= 1;
  swap(a.n4, a.n7), swap(a.inc, a.desc);
}

void join(int a, int b, int c) {
  aint[a].n4 = aint[b].n4 + aint[c].n4;
  aint[a].n7 = aint[b].n7 + aint[c].n7;
  aint[a].inc = max(aint[b].inc + aint[c].n7, aint[b].n4 + aint[c].inc);
  aint[a].desc = max(aint[b].desc + aint[c].n4, aint[b].n7 + aint[c].desc);
}

void build(int nod, int st, int dr) {
  if(st > dr)
    return;
  if(st == dr) {
    aint[nod] = {0, (s[st] == '4'), (s[st] == '7'), 1, 1};
    return;
  }
  int mid = (st + dr) >> 1, a = (nod << 1), b = (a | 1);
  build(a, st, mid), build(b, mid + 1, dr);
  join(nod, a, b);
}

void update(int nod, int st, int dr, int l, int r) {
  if(st > dr || dr < l || r < st)
    return;
  if(l <= st && dr <= r) {
    rev(aint[nod]);
    return;
  }
  int mid = (st + dr) >> 1, a = (nod << 1), b = (a | 1);
  if(aint[nod].rev) {
    aint[nod].rev = 0;
    rev(aint[a]), rev(aint[b]);
  }
  update(a, st, mid, l, r), update(b, mid + 1, dr, l, r);
  join(nod, a, b);
}

int main() {
  cin >> n >> q >> (s + 1);
  build(1, 1, n);
  for(; q; q--) {
    cin >> t;
    if(t == "count")
      cout << aint[1].inc << "\n";
    else {
      cin >> x >> y;
      update(1, 1, n, x, y);
    }
  }
  return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define x first
#define y second
#define ld long double
#define ll long long

using namespace std;

struct Nod {
  bool rev;
  int n4, n7, inc, desc;
};

int n, q, x, y;

char s[1000005];
string t;
Nod aint[4000005];

void rev(Nod &a) {
  a.rev ^= 1;
  swap(a.n4, a.n7), swap(a.inc, a.desc);
}

void join(int a, int b, int c) {
  aint[a].n4 = aint[b].n4 + aint[c].n4;
  aint[a].n7 = aint[b].n7 + aint[c].n7;
  aint[a].inc = max(aint[b].inc + aint[c].n7, aint[b].n4 + aint[c].inc);
  aint[a].desc = max(aint[b].desc + aint[c].n4, aint[b].n7 + aint[c].desc);
}

void build(int nod, int st, int dr) {
  if(st > dr)
    return;
  if(st == dr) {
    aint[nod] = {0, (s[st] == '4'), (s[st] == '7'), 1, 1};
    return;
  }
  int mid = (st + dr) >> 1, a = (nod << 1), b = (a | 1);
  build(a, st, mid), build(b, mid + 1, dr);
  join(nod, a, b);
}

void update(int nod, int st, int dr, int l, int r) {
  if(st > dr || dr < l || r < st)
    return;
  if(l <= st && dr <= r) {
    rev(aint[nod]);
    return;
  }
  int mid = (st + dr) >> 1, a = (nod << 1), b = (a | 1);
  if(aint[nod].rev) {
    aint[nod].rev = 0;
    rev(aint[a]), rev(aint[b]);
  }
  update(a, st, mid, l, r), update(b, mid + 1, dr, l, r);
  join(nod, a, b);
}

int main() {
  ios_base :: sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  cin >> n >> q >> (s + 1);
  build(1, 1, n);
  for(; q; q--) {
    cin >> t;
    if(t == "count")
      cout << aint[1].inc << "\n";
    else {
      cin >> x >> y;
      update(1, 1, n, x, y);
    }
  }
  return 0;
}


/*||>>>> Praveen Ojha <<<<>>>> 24 August 2019 <<<<>>>> 05:02:31 <<<<||*/
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
// #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mod 1000000007
#define inf (int)1e18+5
#define sz(x) (int)x.size()
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define PRINT_TIME cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." <<endl;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename   enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long double ld;
typedef pair<int,int> pii;
//Read Problems Carefully & Check for corner cases N=0,1 ?
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
const int N=1000005;
bool laz[4*N];
struct ST{
	int n4,n7,n47,n74;
};
int n,qq;
ST seg[4*N];
string s;
void build(int st,int en,int pos){
	if(st==en){
		if(s[st]=='4')
			{
				seg[pos].n4=1;
				seg[pos].n47=1;
				seg[pos].n74=1;
			}
		if(s[st]=='7')
			{
				seg[pos].n7=1;
				seg[pos].n47=1;
				seg[pos].n74=1;
			}
			return;

	}
	int mid=(st+en)/2;
	build(st,mid,2*pos);
	build(mid+1,en,2*pos+1);
	int le=2*pos,ri=2*pos+1;
	seg[pos].n4=seg[le].n4+seg[ri].n4;
	seg[pos].n7=seg[le].n7+seg[ri].n7;
	seg[pos].n47=max(seg[le].n4+seg[ri].n47,max(seg[le].n47+seg[ri].n7,seg[le].n4+seg[ri].n7));
	seg[pos].n74=max(seg[le].n7+seg[ri].n74,max(seg[le].n74+seg[ri].n4,seg[le].n7+seg[ri].n4));
}
void change(int pos){
	swap(seg[pos].n4,seg[pos].n7);
	swap(seg[pos].n47,seg[pos].n74);
}
void update(int st,int en,int qst,int qen,int pos){
	if(laz[pos]){
		change(pos);
		if(st!=en){
			laz[2*pos]=!laz[2*pos];
			laz[2*pos+1]=!laz[2*pos+1];
		}
		laz[pos]=!laz[pos];
	}
	if(en<qst || qen<st)
		return;
	if(qst<=st && en<=qen){
		change(pos);
		if(st!=en){
			laz[2*pos]=!laz[2*pos];
			laz[2*pos+1]=!laz[2*pos+1];
		}
		return;
	}
	int mid=(st+en)/2;
	update(st,mid,qst,qen,2*pos);
	update(mid+1,en,qst,qen,2*pos+1);
	int le=2*pos,ri=2*pos+1;
	seg[pos].n4=seg[le].n4+seg[ri].n4;
	seg[pos].n7=seg[le].n7+seg[ri].n7;
	seg[pos].n47=max(seg[le].n4+seg[ri].n47,max(seg[le].n47+seg[ri].n7,seg[le].n4+seg[ri].n7));
	seg[pos].n74=max(seg[le].n7+seg[ri].n74,max(seg[le].n74+seg[ri].n4,seg[le].n7+seg[ri].n4));
}
int32_t main(){__
	cin>>n>>qq;
	cin>>s;
	build(0,n-1,1);
	while(qq--){
		string t;
		cin>>t;
		if(t=="switch"){
			int x,y;
			cin>>x>>y;
			x--,y--;
			update(0,n-1,x,y,1);
		}
		else{
			cout<<seg[1].n47<<"\n";
		}
	}
return 0;
}


/*||>>>> Praveen Ojha <<<<>>>> 24 August 2019 <<<<>>>> 05:02:31 <<<<||*/
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
// #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mod 1000000007
#define inf (int)1e18+5
#define sz(x) (int)x.size()
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define PRINT_TIME cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." <<endl;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename   enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long double ld;
typedef pair<int,int> pii;
//Read Problems Carefully & Check for corner cases N=0,1 ?
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
const int N=1000005;
bool laz[4*N];
struct ST{
	int n4,n7,n47,n74;
};
int n,qq;
ST seg[4*N];
string s;
void build(int st,int en,int pos){
	if(st==en){
		if(s[st]=='4')
			{
				seg[pos].n4=1;
				seg[pos].n47=1;
				seg[pos].n74=1;
			}
		if(s[st]=='7')
			{
				seg[pos].n7=1;
				seg[pos].n47=1;
				seg[pos].n74=1;
			}
			return;
	}
	int mid=(st+en)/2;
	build(st,mid,2*pos);
	build(mid+1,en,2*pos+1);
	int le=2*pos,ri=2*pos+1;
	seg[pos].n4=seg[le].n4+seg[ri].n4;
	seg[pos].n7=seg[le].n7+seg[ri].n7;
	seg[pos].n47=max(seg[le].n4+seg[ri].n47,max(seg[le].n47+seg[ri].n7,seg[le].n4+seg[ri].n7));
	seg[pos].n74=max(seg[le].n7+seg[ri].n74,max(seg[le].n74+seg[ri].n4,seg[le].n7+seg[ri].n4));
}
void change(int pos){
	swap(seg[pos].n4,seg[pos].n7);
	swap(seg[pos].n47,seg[pos].n74);
}
void update(int st,int en,int qst,int qen,int pos){
	if(laz[pos]){
		change(pos);
		if(st!=en){
			laz[2*pos]=!laz[2*pos];
			laz[2*pos+1]=!laz[2*pos+1];
		}
		laz[pos]=!laz[pos];
	}
	if(en<qst || qen<st)
		return;
	if(qst<=st && en<=qen){
		change(pos);
		if(st!=en){
			laz[2*pos]=!laz[2*pos];
			laz[2*pos+1]=!laz[2*pos+1];
		}
		return;
	}
	int mid=(st+en)/2;
	update(st,mid,qst,qen,2*pos);
	update(mid+1,en,qst,qen,2*pos+1);
	int le=2*pos,ri=2*pos+1;
	seg[pos].n4=seg[le].n4+seg[ri].n4;
	seg[pos].n7=seg[le].n7+seg[ri].n7;
	seg[pos].n47=max(seg[le].n4+seg[ri].n47,max(seg[le].n47+seg[ri].n7,seg[le].n4+seg[ri].n7));
	seg[pos].n74=max(seg[le].n7+seg[ri].n74,max(seg[le].n74+seg[ri].n4,seg[le].n7+seg[ri].n4));
}
int32_t main(){__
	cin>>n>>qq;
	cin>>s;
	build(0,n-1,1);
	while(qq--){
		string t;
		cin>>t;
		if(t=="switch"){
			int x,y;
			cin>>x>>y;
			x--,y--;
			update(0,n-1,x,y,1);
		}
		else{
			cout<<seg[1].n47<<"\n";
		}
	}
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fr(i,n)  for(int i = 0;i<n;++i)
#define fri(i,a,b) for(int i= a;i<=b;++i)
#define fro(i,a,b) for(int i= a;i>=b;--i)
#define debug(P) cout<<#P<<" = "<<P<<endl;
#define fi first
#define se second
#define pb(x) push_back(x)
#define  mp(x,y) make_pair(x,y)
#define endl  "\n"
#define  ii  pair<int,int>
#define  LL  long long
#define  maxm(a,b,c)  max(a,max(b,c))
const int MAXN = 1000005;
int a[MAXN];
bool marked[MAXN];
string s;
struct data{
	int n4,n7,n47,n74;
};
data t[4*MAXN];
data make_data(int x){
	data res;
	if(x == '4'){
		res.n4 = 1;
		res.n7 = 0;
	}
	else{
		res.n7 = 1;
		res.n4 = 0;
	}
	res.n47 = 1;
	res.n74 = 1;
	return res;
}
data combine(data l,data r){
	data res;
	res.n4 = l.n4+r.n4;
	res.n7 = l.n7+r.n7;
	res.n47 = max(l.n47+r.n7,l.n4+r.n47);
	res.n74 = max(l.n74+r.n4,l.n7+r.n74);
	return res;
}
void build(int v,int l,int r){
	if(l == r){
		t[v] = make_data(s[l]);
		return;
	}
	int m = (l+r)/2;
	build(2*v,l,m);
	build(2*v+1,m+1,r);
	t[v] = combine(t[2*v],t[2*v+1]);
}
void push(int v){
	if(marked[v]){
		swap(t[2*v].n4,t[2*v].n7);
		swap(t[2*v+1].n4,t[2*v+1].n7);
		swap(t[2*v].n47,t[2*v].n74);
		swap(t[2*v+1].n47,t[2*v+1].n74);
		marked[2*v] = !marked[2*v];
		marked[2*v+1]  = !marked[2*v+1];
		marked[v] = !marked[v];
	}
}
void update(int v,int tl,int tr,int l,int r){
	if(l>tr || r<tl)return;
	if(tl>= l && tr<=r){
		 swap(t[v].n4,t[v].n7);
		 swap(t[v].n47,t[v].n74);
		 marked[v] = true;
		 return;
	}
	push(v);
	int tm = (tl+tr)>>1;
	 update(2*v,tl,tm,l,r);
	 update(2*v+1,tm+1,tr,l,r);
	 t[v] = combine(t[2*v],t[2*v+1]);
}
int main(){
	int n,m,x,y;
	string s1;
	cin>>n>>m;
	cin>>s;
	build(1,0,n-1);
	fr(i,m){
		cin>>s1;
		if(s1 == "count"){
			cout<<t[1].n47<<endl;
		}
		else{
			cin>>x>>y;
			update(1,0,n-1,x-1,y-1);
		}
	}
}


/*||>>>> Praveen Ojha <<<<>>>> 24 August 2019 <<<<>>>> 05:02:31 <<<<||*/
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
// #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mod 1000000007
#define inf (int)1e18+5
#define sz(x) (int)x.size()
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define PRINT_TIME cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." <<endl;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename   enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long double ld;
typedef pair<int,int> pii;
//Read Problems Carefully & Check for corner cases N=0,1 ?
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
const int N=1000005;
struct ST{
	int n4,n7,n47,n74;
};
int n,qq;
ST seg[4*N];
string s;
void build(int st,int en,int pos){
	if(st==en){
		if(s[st]=='4')
			{
				seg[pos].n4=1;
				seg[pos].n47=1;
				seg[pos].n74=1;
			}
		if(s[st]=='7')
			{
				seg[pos].n7=1;
				seg[pos].n47=1;
				seg[pos].n74=1;
			}
			return;

	}
	int mid=(st+en)/2;
	build(st,mid,2*pos);
	build(mid+1,en,2*pos+1);
	int le=2*pos,ri=2*pos+1;
	seg[pos].n4=seg[le].n4+seg[ri].n4;
	seg[pos].n7=seg[le].n7+seg[ri].n7;
	seg[pos].n47=max(seg[le].n4+seg[ri].n47,max(seg[le].n47+seg[ri].n7,seg[le].n4+seg[ri].n7));
	seg[pos].n74=max(seg[le].n7+seg[ri].n74,max(seg[le].n74+seg[ri].n4,seg[le].n7+seg[ri].n4));
}
void update(int st,int en,int qst,int qen,int pos){
	if(en<qst || qen<st)
		return;
	if(qst<=st && en<=qen){
		swap(seg[pos].n4,seg[pos].n7);
		swap(seg[pos].n47,seg[pos].n74);
		return;
	}
	int mid=(st+en)/2;
	update(st,mid,qst,qen,2*pos);
	update(mid+1,en,qst,qen,2*pos+1);
	int le=2*pos,ri=2*pos+1;
	seg[pos].n4=seg[le].n4+seg[ri].n4;
	seg[pos].n7=seg[le].n7+seg[ri].n7;
	seg[pos].n47=max(seg[le].n4+seg[ri].n47,max(seg[le].n47+seg[ri].n7,seg[le].n4+seg[ri].n7));
	seg[pos].n74=max(seg[le].n7+seg[ri].n74,max(seg[le].n74+seg[ri].n4,seg[le].n7+seg[ri].n4));
}
int32_t main(){__
	cin>>n>>qq;
	cin>>s;
	build(0,n-1,1);
	while(qq--){
		string t;
		cin>>t;
		if(t=="switch"){
			int x,y;
			cin>>x>>y;
			x--,y--;
			update(0,n-1,x,y,1);
		}
		else{
			cout<<seg[1].n47<<"\n";
		}
	}
return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <stack>
#include <queue>
#include <deque>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

// template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//  order_of_key (k) : Number of items strictly smaller than k .
//  find_by_order(k) : K-th element in a set (counting from zero).
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define show(a) cerr << #a <<" -> "<< a <<" "
#define nl cerr <<"\n"
#define fo(a, b, c, d) for(int (a) = (b); (a) <= (c); (a) += (d))
#define foo(a, b, c ,d) for(int (a) = (b); (a) >= (c); (a) -= (d))
//#define int ll

const int N = (1 << 20) - 1;
const int oo = 1e9 + 5;

int n, m;
string s;
bool ch[N * 4];

struct Node {
    int ans, c4, c7;
} t[N * 4];

void build (int v=1, int tl=1, int tr=n) {
    if (tl == tr) {
        if (s[tl] == '4') {
            t[v].ans = 1;
            t[v].c4 = 1;
            t[v].c7 = 0;
        }
        if (s[tl] == '7') {
            t[v].ans = 1;
            t[v].c4 = 0;
            t[v].c7 = 1;
        }
        return;
    }

    int tm = (tl + tr) / 2;
    build(v*2, tl, tm);
    build(v*2+1, tm+1, tr);

    t[v].c4 = t[v*2].c4 + t[v*2+1].c4;
    t[v].c7 = t[v*2].c7 + t[v*2+1].c7;
    t[v].ans = max( {t[v*2].c4 + t[v*2+1].ans,
                     t[v*2].ans + t[v*2+1].c7,
                     t[v*2].c4 + t[v*2+1].c7,
                     t[v].c4, t[v].c7} );
}

void push(int v, int tl, int tr) {
    if (ch[v]) {
        swap(t[v].c4, t[v].c7);
        t[v].ans = max( {t[v*2].c7 + t[v*2+1].ans,
                     t[v*2].ans + t[v*2+1].c4,
                     t[v*2].c7 + t[v*2+1].c4,
                     t[v].c4, t[v].c7} );

        if (tl < tr) {
            ch[v*2] ^= 1;
            ch[v*2+1] ^= 1;
        }
        ch[v] = 0;
    }
}

void upd (int l, int r, int v=1, int tl=1, int tr=n) {
    push(v, tl, tr);
    if (r < tl || tr < l) { return; }
    if (l <= tl && tr <= r) {
        ch[v] ^= 1;
        push(v, tl, tr);
        return;
    }

    int tm = (tl + tr) / 2;
    upd (l, r, v*2, tl, tm);
    upd (l, r, v*2+1, tm+1, tr);

    t[v].c4 = t[v*2].c4 + t[v*2+1].c4;
    t[v].c7 = t[v*2].c7 + t[v*2+1].c7;
    t[v].ans = max( {t[v*2].c4 + t[v*2+1].ans,
                     t[v*2].ans + t[v*2+1].c7,
                     t[v*2].c4 + t[v*2+1].c7,
                     t[v].c4, t[v].c7} );
}

void solve() {
    cin >> n >> m;
    cin >> s; s = '#' + s;
    build();
    for (int it = 1; it <= m; ++it) {
        string type;
        cin >> type;
        if (type == "count") {
            cout << t[1].ans <<'\n';
        }
        else {
            int l, r;
            cin >> l >> r;
            upd(l, r);
        }
    }
}

 main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int tests = 1;
	//cin >> tests;
	while (tests --) {
		solve();
	}
	return 0;
}
/*
	“I’m not gonna run away, I never go back on my word! That’s my nindo: my ninja way.” Naruto
═══════════░▓
══════════░▓▓
════════░▓░░▓
═══════▓▓░░░▓
▓════░▓░░░░░▓══════════░▓▓░
▓═══▒▓░░░░░░▓░══════░▓▓░░▓░
▓══▓▒═░░░░░░░▓════░▓▓░░░░▓
░▓▓░═░░░░░░░░▓══░▒▓░░░░░▒▓
░░░░░░░░░░░░░▒▓▓▓░░░░░░═▓═════░▓▓▓▓▓
░░░░░░░░░░░░░░░░░░░░░░░░▓═░▓▓▓▓░░▒▓
░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓░░░═░▒▓░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░═░▓▓▒
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▒▓▓▒
░░░░░░░░░░░░░░░░░══░░░░░░░░░▒▓▓▓▓▓▓▓▓▓▓▓
░══════════░░════░▒▒░░░═░░░░▒░░░░░░░░░▓▓
▒░══░▒▒▓▓██▓══░▒█▓░════▒▓░░░═░░░═░░▒▓▓▒
▓█████████▓░▒▓███═══░▒██▒═░░░░░░░▒▓▓▒
▓█▓▓▓▓▓▓▓█▓█████══░▓████═══▒▒═░░░░░▓▓
▓▓▓▓▓▓▓▓▓██▓▓▓█▒░▓█████▒══▒▓▒═░░░░══▓▓▓▓
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓████▓▓█░═▒▒█▓═░░░░░░▒▒▓
▓▓▓▓▓▓▓▓▓▓▓▓▓████▓▓▓▓▓▓═▒▓██▓═░░░═░▓▓▓
▓█▓▓▓▓▓▓▓▓▓▓▓██▓▓▓▓▓▓█▒▒████▓═░░░░▓
▒▒▓████████████████▓▓▓▓██▓▓█▓═░░═▓█
▒▒░░▒░░░░░░▒░▒▒▒▓▓██████▓▓▓█▓═░═▒▓█▓
▒██▒░░══════░▓░═░░░▒▒▓████▓▓█══░█══▓
▒▒▒▒░▒═░░░═░▓░░░░░░░░░░▒▓████══▓▒══▓
▒▒▓▓░▓═░░░═▒▓░░░░░░░░░░░░░▓██═▓▓══░▓
▒▓▓▒░▓═░░═▒▓░░░░░░░░░░░░░══▒▒▒██▒══▓
▓▒░░▒▓═══░▓░░░░░░░░░░░░░░▓▓▓▒░▓██▓═▓
▓▓░░▒▓═░░▒▒░░░░░░░░░░░░░░▓═▒█░░▓██▓▓
▓█▒░▒▓═▓▓▒░░░░░░░░░░░░░░░▓══██▒▒▓██
░░░░▒▓▒█▓░░░░░░░░░░░░░░░░▓═▒█▓▓▒██░
░░░░▒█▓▒░░░░▒░░░░░░░░░░░░░▓▓▓▒▒▒▒
▒░░░▒█▒░░░░▒▒▒▒▒▒▒▒▒▒▒░░░░▒▓▒░▓░
█▒░░▒▓░░░░░░░░░░░░▒▒▒▒▒░░░░░░░▓
▓▓░░▒▒░░░░░░░░░░░░░░░░░░░░░░░░▓
▒▓░░░░░░░▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░░▓
▒▓░░░░░░░░░░░░░░░░░▒░░░░░░░░░░░▒▓
▒▓░░░░░░░░░░░░░░▒▒░░░░░░░░░░░░░░▓▒
▒▓░░░░░░░▒▒▒▒▒▒▒▒▒░░░░░░░░░░▒▓▓▒▒█░
▒▓▒░░░░░░▒▒░░░░░░░░░░░░░░░░░▒▓██▓▒
▒▓▓░░░░░░░░░░░░░░░░░░▒▒▒▒░░░░▓░
░▒▓▓░░░░░░░░░░░░░░░░▒▒▒▒▓▓▓░▓
░▒▓▓▓▒░░░░░░░░░░░░░░░░░░░▒▓█▓
░░█▒▒▓▓▒░░░░░░░░░░░░░░░░▒▒▓▒
░░▓▓▒▒▒▓▓▒░░░░░░░░░░░░░░░▒▓
░░▒█▒▒▒▒▒▓▓▒▒░░░░░░░░░░░░▓
░░░▓▓▒▒▒▒▒▒▓▓▓▒░░░░░░░░░░▓
░░░▒▓▒▒▒▒▒▒▒▒▒▓▓▓▒░░░░░░░▓
░░░░▓▒▒▒▒▒▒▒▒▒▒▓▓▓▒▒░░░░▓░
░░░░▓▓▒▒▒▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓░
░░░░░▓▒▒▒▒▒▓░
▓▓██▓▓▓██▓▓██▒
▓▓██▓▓▓██▓▓██▒
▓▓██▓▓▓██▓▓██▒
▓▓██▓▓▓██▓▓██▒
*/


#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <stack>
#include <queue>
#include <deque>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

// template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//  order_of_key (k) : Number of items strictly smaller than k .
//  find_by_order(k) : K-th element in a set (counting from zero).
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define show(a) cerr << #a <<" -> "<< a <<" "
#define nl cerr <<"\n"
#define fo(a, b, c, d) for(int (a) = (b); (a) <= (c); (a) += (d))
#define foo(a, b, c ,d) for(int (a) = (b); (a) >= (c); (a) -= (d))
//#define int ll

const int N = (1 << 20) - 1;
const int oo = 1e9 + 5;

int n, m;
string s;
bool ch[N * 4];

struct Node {
    int ans, rans, c4, c7;
} t[N * 4];

void build (int v=1, int tl=1, int tr=n) {
    if (tl == tr) {
        if (s[tl] == '4') {
            t[v].ans = 1;
            t[v].rans = 1;
            t[v].c4 = 1;
            t[v].c7 = 0;
        }
        if (s[tl] == '7') {
            t[v].ans = 1;
            t[v].rans = 1;
            t[v].c4 = 0;
            t[v].c7 = 1;
        }
        return;
    }

    int tm = (tl + tr) / 2;
    build(v*2, tl, tm);
    build(v*2+1, tm+1, tr);

    t[v].c4 = t[v*2].c4 + t[v*2+1].c4;
    t[v].c7 = t[v*2].c7 + t[v*2+1].c7;
    t[v].ans = max( {t[v*2].c4 + t[v*2+1].ans,
                     t[v*2].ans + t[v*2+1].c7,
                     t[v*2].c4 + t[v*2+1].c7,
                     t[v].c4, t[v].c7} );
    t[v].rans = max( {t[v*2].c7 + t[v*2+1].rans,
                     t[v*2].rans + t[v*2+1].c4,
                     t[v*2].c7 + t[v*2+1].c4,
                     t[v].c4, t[v].c7} );
}

void push(int v, int tl, int tr) {
    if (ch[v]) {
        swap(t[v].c4, t[v].c7);
        swap(t[v].ans, t[v].rans);
        if (tl < tr) {
            ch[v*2] ^= 1;
            ch[v*2+1] ^= 1;
        }
        ch[v] = 0;
    }
}

void upd (int l, int r, int v=1, int tl=1, int tr=n) {
    push(v, tl, tr);
    if (r < tl || tr < l) { return; }
    if (l <= tl && tr <= r) {
        ch[v] ^= 1;
        push(v, tl, tr);
        return;
    }

    int tm = (tl + tr) / 2;
    upd (l, r, v*2, tl, tm);
    upd (l, r, v*2+1, tm+1, tr);

    t[v].c4 = t[v*2].c4 + t[v*2+1].c4;
    t[v].c7 = t[v*2].c7 + t[v*2+1].c7;
    t[v].ans = max( {t[v*2].c4 + t[v*2+1].ans,
                     t[v*2].ans + t[v*2+1].c7,
                     t[v*2].c4 + t[v*2+1].c7,
                     t[v].c4, t[v].c7} );
    t[v].rans = max( {t[v*2].c7 + t[v*2+1].rans,
                     t[v*2].rans + t[v*2+1].c4,
                     t[v*2].c7 + t[v*2+1].c4,
                     t[v].c4, t[v].c7} );
}

void solve() {
    cin >> n >> m;
    cin >> s; s = '#' + s;
    build();
    for (int it = 1; it <= m; ++it) {
        string type;
        cin >> type;
        if (type == "count") {
            cout << t[1].ans <<'\n';
        }
        else {
            int l, r;
            cin >> l >> r;
            upd(l, r);
        }
    }
}

 main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int tests = 1;
	//cin >> tests;
	while (tests --) {
		solve();
	}
	return 0;
}
/*
	“I’m not gonna run away, I never go back on my word! That’s my nindo: my ninja way.” Naruto
═══════════░▓
══════════░▓▓
════════░▓░░▓
═══════▓▓░░░▓
▓════░▓░░░░░▓══════════░▓▓░
▓═══▒▓░░░░░░▓░══════░▓▓░░▓░
▓══▓▒═░░░░░░░▓════░▓▓░░░░▓
░▓▓░═░░░░░░░░▓══░▒▓░░░░░▒▓
░░░░░░░░░░░░░▒▓▓▓░░░░░░═▓═════░▓▓▓▓▓
░░░░░░░░░░░░░░░░░░░░░░░░▓═░▓▓▓▓░░▒▓
░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓░░░═░▒▓░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░═░▓▓▒
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▒▓▓▒
░░░░░░░░░░░░░░░░░══░░░░░░░░░▒▓▓▓▓▓▓▓▓▓▓▓
░══════════░░════░▒▒░░░═░░░░▒░░░░░░░░░▓▓
▒░══░▒▒▓▓██▓══░▒█▓░════▒▓░░░═░░░═░░▒▓▓▒
▓█████████▓░▒▓███═══░▒██▒═░░░░░░░▒▓▓▒
▓█▓▓▓▓▓▓▓█▓█████══░▓████═══▒▒═░░░░░▓▓
▓▓▓▓▓▓▓▓▓██▓▓▓█▒░▓█████▒══▒▓▒═░░░░══▓▓▓▓
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓████▓▓█░═▒▒█▓═░░░░░░▒▒▓
▓▓▓▓▓▓▓▓▓▓▓▓▓████▓▓▓▓▓▓═▒▓██▓═░░░═░▓▓▓
▓█▓▓▓▓▓▓▓▓▓▓▓██▓▓▓▓▓▓█▒▒████▓═░░░░▓
▒▒▓████████████████▓▓▓▓██▓▓█▓═░░═▓█
▒▒░░▒░░░░░░▒░▒▒▒▓▓██████▓▓▓█▓═░═▒▓█▓
▒██▒░░══════░▓░═░░░▒▒▓████▓▓█══░█══▓
▒▒▒▒░▒═░░░═░▓░░░░░░░░░░▒▓████══▓▒══▓
▒▒▓▓░▓═░░░═▒▓░░░░░░░░░░░░░▓██═▓▓══░▓
▒▓▓▒░▓═░░═▒▓░░░░░░░░░░░░░══▒▒▒██▒══▓
▓▒░░▒▓═══░▓░░░░░░░░░░░░░░▓▓▓▒░▓██▓═▓
▓▓░░▒▓═░░▒▒░░░░░░░░░░░░░░▓═▒█░░▓██▓▓
▓█▒░▒▓═▓▓▒░░░░░░░░░░░░░░░▓══██▒▒▓██
░░░░▒▓▒█▓░░░░░░░░░░░░░░░░▓═▒█▓▓▒██░
░░░░▒█▓▒░░░░▒░░░░░░░░░░░░░▓▓▓▒▒▒▒
▒░░░▒█▒░░░░▒▒▒▒▒▒▒▒▒▒▒░░░░▒▓▒░▓░
█▒░░▒▓░░░░░░░░░░░░▒▒▒▒▒░░░░░░░▓
▓▓░░▒▒░░░░░░░░░░░░░░░░░░░░░░░░▓
▒▓░░░░░░░▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░░▓
▒▓░░░░░░░░░░░░░░░░░▒░░░░░░░░░░░▒▓
▒▓░░░░░░░░░░░░░░▒▒░░░░░░░░░░░░░░▓▒
▒▓░░░░░░░▒▒▒▒▒▒▒▒▒░░░░░░░░░░▒▓▓▒▒█░
▒▓▒░░░░░░▒▒░░░░░░░░░░░░░░░░░▒▓██▓▒
▒▓▓░░░░░░░░░░░░░░░░░░▒▒▒▒░░░░▓░
░▒▓▓░░░░░░░░░░░░░░░░▒▒▒▒▓▓▓░▓
░▒▓▓▓▒░░░░░░░░░░░░░░░░░░░▒▓█▓
░░█▒▒▓▓▒░░░░░░░░░░░░░░░░▒▒▓▒
░░▓▓▒▒▒▓▓▒░░░░░░░░░░░░░░░▒▓
░░▒█▒▒▒▒▒▓▓▒▒░░░░░░░░░░░░▓
░░░▓▓▒▒▒▒▒▒▓▓▓▒░░░░░░░░░░▓
░░░▒▓▒▒▒▒▒▒▒▒▒▓▓▓▒░░░░░░░▓
░░░░▓▒▒▒▒▒▒▒▒▒▒▓▓▓▒▒░░░░▓░
░░░░▓▓▒▒▒▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓░
░░░░░▓▒▒▒▒▒▓░
▓▓██▓▓▓██▓▓██▒
▓▓██▓▓▓██▓▓██▒
▓▓██▓▓▓██▓▓██▒
▓▓██▓▓▓██▓▓██▒
*/


#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <stack>
#include <queue>
#include <deque>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

// template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//  order_of_key (k) : Number of items strictly smaller than k .
//  find_by_order(k) : K-th element in a set (counting from zero).
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define show(a) cerr << #a <<" -> "<< a <<" "
#define nl cerr <<"\n"
#define fo(a, b, c, d) for(int (a) = (b); (a) <= (c); (a) += (d))
#define foo(a, b, c ,d) for(int (a) = (b); (a) >= (c); (a) -= (d))
//#define int ll

const int N = (1 << 20) - 1;
const int oo = 1e9 + 5;

int n, m;
string s;
bool ch[N * 4];

struct Node {
    int ans, c4, c7;
} t[N * 4];

void build (int v=1, int tl=1, int tr=n) {
    if (tl == tr) {
        if (s[tl] == '4') {
            t[v].ans = 1;
            t[v].c4 = 1;
            t[v].c7 = 0;
        }
        if (s[tl] == '7') {
            t[v].ans = 1;
            t[v].c4 = 0;
            t[v].c7 = 1;
        }
        return;
    }

    int tm = (tl + tr) / 2;
    build(v*2, tl, tm);
    build(v*2+1, tm+1, tr);

    t[v].c4 = t[v*2].c4 + t[v*2+1].c4;
    t[v].c7 = t[v*2].c7 + t[v*2+1].c7;
    t[v].ans = max( {t[v*2].c4 + t[v*2+1].ans,
                     t[v*2].ans + t[v*2+1].c7,
                     t[v*2].c4 + t[v*2+1].c7,
                     t[v].c4, t[v].c7} );
}

void push(int v, int tl, int tr) {
    if (ch[v]) {
        swap(t[v].c4, t[v].c7);
        t[v].ans = max( {t[v*2].c7 + t[v*2+1].ans,
                     t[v*2].ans + t[v*2+1].c4,
                     t[v*2].c7 + t[v*2+1].c4,
                     t[v].c4, t[v].c7} );

        if (tl < tr) {
            ch[v*2] ^= 1;
            ch[v*2+1] ^= 1;
        }
        ch[v] = 0;
    }
}

void upd (int l, int r, int v=1, int tl=1, int tr=n) {
    push(v, tl, tr);
    if (r < tl || tr < l) { return; }
    if (l <= tl && tr <= r) {
        ch[v] ^= 1;
        push(v, tl, tr);
        return;
    }

    int tm = (tl + tr) / 2;
    upd (l, r, v*2, tl, tm);
    upd (l, r, v*2+1, tm+1, tr);

    t[v].c4 = t[v*2].c4 + t[v*2+1].c4;
    t[v].c7 = t[v*2].c7 + t[v*2+1].c7;
    t[v].ans = max( {t[v*2].c4 + t[v*2+1].ans,
                     t[v*2].ans + t[v*2+1].c7,
                     t[v*2].c4 + t[v*2+1].c7,
                     t[v].c4, t[v].c7} );
}

void solve() {
    cin >> n >> m;
    cin >> s; s = '#' + s;
    build();
    for (int it = 1; it <= m; ++it) {
        string type;
        cin >> type;
        if (type == "count") {
            push(1, 1, n);
            cout << t[1].ans <<'\n';
        }
        else {
            int l, r;
            cin >> l >> r;
            upd(l, r);
        }
    }
}

 main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int tests = 1;
	//cin >> tests;
	while (tests --) {
		solve();
	}
	return 0;
}
/*
	“I’m not gonna run away, I never go back on my word! That’s my nindo: my ninja way.” Naruto
═══════════░▓
══════════░▓▓
════════░▓░░▓
═══════▓▓░░░▓
▓════░▓░░░░░▓══════════░▓▓░
▓═══▒▓░░░░░░▓░══════░▓▓░░▓░
▓══▓▒═░░░░░░░▓════░▓▓░░░░▓
░▓▓░═░░░░░░░░▓══░▒▓░░░░░▒▓
░░░░░░░░░░░░░▒▓▓▓░░░░░░═▓═════░▓▓▓▓▓
░░░░░░░░░░░░░░░░░░░░░░░░▓═░▓▓▓▓░░▒▓
░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓░░░═░▒▓░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░═░▓▓▒
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▒▓▓▒
░░░░░░░░░░░░░░░░░══░░░░░░░░░▒▓▓▓▓▓▓▓▓▓▓▓
░══════════░░════░▒▒░░░═░░░░▒░░░░░░░░░▓▓
▒░══░▒▒▓▓██▓══░▒█▓░════▒▓░░░═░░░═░░▒▓▓▒
▓█████████▓░▒▓███═══░▒██▒═░░░░░░░▒▓▓▒
▓█▓▓▓▓▓▓▓█▓█████══░▓████═══▒▒═░░░░░▓▓
▓▓▓▓▓▓▓▓▓██▓▓▓█▒░▓█████▒══▒▓▒═░░░░══▓▓▓▓
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓████▓▓█░═▒▒█▓═░░░░░░▒▒▓
▓▓▓▓▓▓▓▓▓▓▓▓▓████▓▓▓▓▓▓═▒▓██▓═░░░═░▓▓▓
▓█▓▓▓▓▓▓▓▓▓▓▓██▓▓▓▓▓▓█▒▒████▓═░░░░▓
▒▒▓████████████████▓▓▓▓██▓▓█▓═░░═▓█
▒▒░░▒░░░░░░▒░▒▒▒▓▓██████▓▓▓█▓═░═▒▓█▓
▒██▒░░══════░▓░═░░░▒▒▓████▓▓█══░█══▓
▒▒▒▒░▒═░░░═░▓░░░░░░░░░░▒▓████══▓▒══▓
▒▒▓▓░▓═░░░═▒▓░░░░░░░░░░░░░▓██═▓▓══░▓
▒▓▓▒░▓═░░═▒▓░░░░░░░░░░░░░══▒▒▒██▒══▓
▓▒░░▒▓═══░▓░░░░░░░░░░░░░░▓▓▓▒░▓██▓═▓
▓▓░░▒▓═░░▒▒░░░░░░░░░░░░░░▓═▒█░░▓██▓▓
▓█▒░▒▓═▓▓▒░░░░░░░░░░░░░░░▓══██▒▒▓██
░░░░▒▓▒█▓░░░░░░░░░░░░░░░░▓═▒█▓▓▒██░
░░░░▒█▓▒░░░░▒░░░░░░░░░░░░░▓▓▓▒▒▒▒
▒░░░▒█▒░░░░▒▒▒▒▒▒▒▒▒▒▒░░░░▒▓▒░▓░
█▒░░▒▓░░░░░░░░░░░░▒▒▒▒▒░░░░░░░▓
▓▓░░▒▒░░░░░░░░░░░░░░░░░░░░░░░░▓
▒▓░░░░░░░▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░░▓
▒▓░░░░░░░░░░░░░░░░░▒░░░░░░░░░░░▒▓
▒▓░░░░░░░░░░░░░░▒▒░░░░░░░░░░░░░░▓▒
▒▓░░░░░░░▒▒▒▒▒▒▒▒▒░░░░░░░░░░▒▓▓▒▒█░
▒▓▒░░░░░░▒▒░░░░░░░░░░░░░░░░░▒▓██▓▒
▒▓▓░░░░░░░░░░░░░░░░░░▒▒▒▒░░░░▓░
░▒▓▓░░░░░░░░░░░░░░░░▒▒▒▒▓▓▓░▓
░▒▓▓▓▒░░░░░░░░░░░░░░░░░░░▒▓█▓
░░█▒▒▓▓▒░░░░░░░░░░░░░░░░▒▒▓▒
░░▓▓▒▒▒▓▓▒░░░░░░░░░░░░░░░▒▓
░░▒█▒▒▒▒▒▓▓▒▒░░░░░░░░░░░░▓
░░░▓▓▒▒▒▒▒▒▓▓▓▒░░░░░░░░░░▓
░░░▒▓▒▒▒▒▒▒▒▒▒▓▓▓▒░░░░░░░▓
░░░░▓▒▒▒▒▒▒▒▒▒▒▓▓▓▒▒░░░░▓░
░░░░▓▓▒▒▒▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓░
░░░░░▓▒▒▒▒▒▓░
▓▓██▓▓▓██▓▓██▒
▓▓██▓▓▓██▓▓██▒
▓▓██▓▓▓██▓▓██▒
▓▓██▓▓▓██▓▓██▒
*/


#include<bits/stdc++.h>
#include <iomanip>
#define ll long long int
#define ld long double
#define IOS cin.tie(NULL);cout.tie(NULL)
#define F first
#define S second
#define pb push_back
#define forn(i,n) for(int i=0;i<(int)n;i++)
using namespace std;
ll const mod=1000000007;
/*
ll arr1[1000009];
ll parent[1000009];
void sievefun(ll n){
    for(ll i=2;i<=n;i++){
        if(arr1[i]==0){
                parent[i]=i;
            for(ll j=i*i;j<=n;j+=i){
                if(arr1[j]==0)
                parent[j]=i;
                arr1[j]=1;
            }
        }
    }
}
*/
ll power(ll x, ll y) {
	ll temp;
	if( y == 0)
		return 1;
	temp = power(x, y/2)%mod;
	if (y%2 == 0)
		return ((temp%mod)*(temp%mod))%mod;
	else
		return (((x)%mod)*(temp*temp)%mod)%mod;
}
ll gcd(ll a, ll b){
if (a == 0)
    return b;
return gcd(b % a, a);
}
ll lcm(ll a, ll b)
{
return (a*b)/gcd(a, b);
}
struct tt{
    int a;
    int b;
    int c;
    int d;
};
string arr;
tt tree[5000000];
int lazy[5000000];
void change(int node){
    swap(tree[node].a,tree[node].c);
    swap(tree[node].b,tree[node].d);
}
void trees(int start,int end,int node){
    int mid=start+(end-start)/2;
    if(start==end){
        if(arr[start-1]=='4'){
            tree[node].a=1;tree[node].b=0;tree[node].c=0,tree[node].d=0;
        }else{
            tree[node].a=0;tree[node].b=0;tree[node].c=1,tree[node].d=0;
        }
        return ;
    }
    trees(start,mid,2*node);
    trees(mid+1,end,2*node+1);
    tt L=tree[2*node];tt R=tree[2*node+1];
    tree[node].a=L.a+R.a;
    tree[node].c=L.c+R.c;
    tree[node].b=max(L.a+max(R.b,R.c),L.b+R.c);
    tree[node].d=max(L.c+max(R.a,R.d),L.d+R.a);
}
void update(int start,int end,int node,int l,int r){
    if(start>r||end<l)
        return;
    if(lazy[node]!=0){
        change(2*node+1);change(2*node);
        lazy[node]=0;
        if(start!=end){
            lazy[2*node]++;
            lazy[2*node]%=2;
            lazy[2*node+1]++;
            lazy[2*node+1]%=2;
        }

    }
    int mid=start+(end-start)/2;
    if(end<l||start>r)
        return;
    if(start>=l&&end<=r){
        change(node);
        lazy[node]^=1;
        return;

    }
        update(start,mid,2*node,l,r);
        update(mid+1,end,2*node+1,l,r);
        tt L=tree[2*node];tt R=tree[2*node+1];
        tree[node].a=L.a+R.a;
        tree[node].c=L.c+R.c;
        tree[node].b=max(L.a+max(R.b,R.c),L.b+R.c);
        tree[node].d=max(L.c+max(R.a,R.d),L.d+R.a);

}
int main(){
    IOS;
    int n,m;
    cin>>n>>m;
    string str;
    string count="count";
    cin>>arr;
    trees(1,n,1);
    //cout<<max(tree[1].a,max(tree[1].b,tree[1].c));

    int l,r;
    forn(i,m){
        cin>>str;
        if(str==count)
            printf("%d\n",max(tree[1].a,max(tree[1].b,tree[1].c)));
        else{
            scanf("%d %d",&l,&r);
            update(1,n,1,l,r);

        }
    }
}


#include<bits/stdc++.h>
#include <iomanip>
#define ll long long int
#define ld long double
#define IOS cin.tie(NULL);cout.tie(NULL)
#define F first
#define S second
#define pb push_back
#define forn(i,n) for(int i=0;i<(int)n;i++)
using namespace std;
ll const mod=1000000007;
/*
ll arr1[1000009];
ll parent[1000009];
void sievefun(ll n){
    for(ll i=2;i<=n;i++){
        if(arr1[i]==0){
                parent[i]=i;
            for(ll j=i*i;j<=n;j+=i){
                if(arr1[j]==0)
                parent[j]=i;
                arr1[j]=1;
            }
        }
    }
}
*/
ll power(ll x, ll y) {
	ll temp;
	if( y == 0)
		return 1;
	temp = power(x, y/2)%mod;
	if (y%2 == 0)
		return ((temp%mod)*(temp%mod))%mod;
	else
		return (((x)%mod)*(temp*temp)%mod)%mod;
}
ll gcd(ll a, ll b){
if (a == 0)
    return b;
return gcd(b % a, a);
}
ll lcm(ll a, ll b)
{
return (a*b)/gcd(a, b);
}
struct tt{
    ll a;
    ll b;
    ll c;
    ll d;
};
ll arr[1000009];
tt tree[5000000];
ll lazy[5000000];
void change(ll node){
    ll a=tree[node].a,b=tree[node].b,c=tree[node].c,d=tree[node].d;
        tree[node].a=c;
        tree[node].c=a;
        tree[node].b=d;
        tree[node].d=b;

}
void trees(ll start,ll end,ll node){
    ll mid=start+(end-start)/2;
    if(start==end){
        if(arr[start-1]==4){
            tree[node].a=1;tree[node].b=0;tree[node].c=0,tree[node].d=0;
        }else{
            tree[node].a=0;tree[node].b=0;tree[node].c=1,tree[node].d=0;
        }
        return ;
    }
    trees(start,mid,2*node);
    trees(mid+1,end,2*node+1);
    tt L=tree[2*node];tt R=tree[2*node+1];
    tree[node].a=L.a+R.a;
    tree[node].c=L.c+R.c;
    tree[node].b=max(L.a+max(R.b,R.c),L.b+R.c);
    tree[node].d=max(L.c+max(R.a,R.d),L.d+R.a);
}
void update(ll start,ll end,ll node,ll l,ll r){
    if(lazy[node]!=0){
        change(2*node+1);change(2*node);
        lazy[node]=0;
        if(start!=end){
            lazy[2*node]++;
            lazy[2*node]%=2;
            lazy[2*node+1]++;
            lazy[2*node+1]%=2;
        }

    }
    if(start>r||end<l)
        return;

    ll mid=start+(end-start)/2;
    if(end<l||start>r)
        return;
    if(start>=l&&end<=r){
        ll a=tree[node].a,b=tree[node].b,c=tree[node].c,d=tree[node].d;
        tree[node].a=c;
        tree[node].c=a;
        tree[node].b=d;
        tree[node].d=b;
        lazy[node]^=1;
        return;

    }
        update(start,mid,2*node,l,r);
        update(mid+1,end,2*node+1,l,r);
        tt L=tree[2*node];tt R=tree[2*node+1];
        tree[node].a=L.a+R.a;
        tree[node].c=L.c+R.c;
        tree[node].b=max(L.a+max(R.b,R.c),L.b+R.c);
        tree[node].d=max(L.c+max(R.a,R.d),L.d+R.a);

}
int main(){
    IOS;
    ll n,m;
    cin>>n>>m;
    string str;
    string count="count";
    cin>>str;
    forn(i,n){
        arr[i]=str[i]-'0';
    }
    trees(1,n,1);
    //cout<<max(tree[1].a,max(tree[1].b,tree[1].c));

    ll l,r;
    forn(i,m){
        cin>>str;
        if(str==count)
            printf("%lld\n",max(tree[1].a,max(tree[1].b,tree[1].c)));
        else{
            scanf("%lld %lld",&l,&r);
            update(1,n,1,l,r);

        }
    }
}


#include<bits/stdc++.h>
#include <iomanip>
#define ll long long int
#define ld long double
#define IOS cin.tie(NULL);cout.tie(NULL)
#define F first
#define S second
#define pb push_back
#define forn(i,n) for(int i=0;i<(int)n;i++)
using namespace std;
ll const mod=1000000007;
/*
ll arr1[1000009];
ll parent[1000009];
void sievefun(ll n){
    for(ll i=2;i<=n;i++){
        if(arr1[i]==0){
                parent[i]=i;
            for(ll j=i*i;j<=n;j+=i){
                if(arr1[j]==0)
                parent[j]=i;
                arr1[j]=1;
            }
        }
    }
}
*/
ll power(ll x, ll y) {
	ll temp;
	if( y == 0)
		return 1;
	temp = power(x, y/2)%mod;
	if (y%2 == 0)
		return ((temp%mod)*(temp%mod))%mod;
	else
		return (((x)%mod)*(temp*temp)%mod)%mod;
}
ll gcd(ll a, ll b){
if (a == 0)
    return b;
return gcd(b % a, a);
}
ll lcm(ll a, ll b)
{
return (a*b)/gcd(a, b);
}
struct tt{
    ll a;
    ll b;
    ll c;
};
ll arr[1000009];
tt tree[5000000];
void trees(ll start,ll end,ll node){
    ll mid=start+(end-start)/2;
    if(start==end){
        if(arr[start-1]==4){
            tree[node].a=1;tree[node].b=0;tree[node].c=0;
        }else{
            tree[node].a=0;tree[node].b=0;tree[node].c=1;
        }
        return ;
    }
    trees(start,mid,2*node);
    trees(mid+1,end,2*node+1);
    tt L=tree[2*node];tt R=tree[2*node+1];
    tree[node].a=L.a+R.a;
    tree[node].c=L.c+R.c;
    tree[node].b=max(L.a+max(R.b,R.c),L.b+R.c);
}
void update(ll start,ll end,ll node,ll l,ll r){
    ll mid=start+(end-start)/2;
    if(end<l||start>r)
        return;
    if(start==end){
        if(arr[start-1]==4){
            tree[node].a=0;tree[node].b=0;tree[node].c=1;
            arr[start-1]=7;
        }else{
            tree[node].a=1;tree[node].b=0;tree[node].c=0;
            arr[start-1]=4;
        }
        return ;
    }

    else{
        update(start,mid,2*node,l,r);
        update(mid+1,end,2*node+1,l,r);
        tt L=tree[2*node];tt R=tree[2*node+1];
        tree[node].a=L.a+R.a;
        tree[node].c=L.c+R.c;
        tree[node].b=max(L.a+max(R.b,R.c),L.b+R.c);

    }
}
int main(){
    IOS;
    ll n,m;
    cin>>n>>m;
    string str;
    string count="count";
    cin>>str;
    forn(i,n){
        arr[i]=str[i]-'0';
    }
    trees(1,n,1);
    //cout<<max(tree[1].a,max(tree[1].b,tree[1].c));

    ll l,r;
    forn(i,m){
        cin>>str;
        if(str==count)
            printf("%lld\n",max(tree[1].a,max(tree[1].b,tree[1].c)));
        else{
            scanf("%lld %lld",&l,&r);
            update(1,n,1,l,r);

        }
    }
}


#include<bits/stdc++.h>
#include <iomanip>
#define ll long long int
#define ld long double
#define IOS cin.tie(NULL);cout.tie(NULL)
#define F first
#define S second
#define pb push_back
#define forn(i,n) for(int i=0;i<(int)n;i++)
using namespace std;
ll const mod=1000000007;
/*
ll arr1[1000009];
ll parent[1000009];
void sievefun(ll n){
    for(ll i=2;i<=n;i++){
        if(arr1[i]==0){
                parent[i]=i;
            for(ll j=i*i;j<=n;j+=i){
                if(arr1[j]==0)
                parent[j]=i;
                arr1[j]=1;
            }
        }
    }
}
*/
ll power(ll x, ll y) {
	ll temp;
	if( y == 0)
		return 1;
	temp = power(x, y/2)%mod;
	if (y%2 == 0)
		return ((temp%mod)*(temp%mod))%mod;
	else
		return (((x)%mod)*(temp*temp)%mod)%mod;
}
ll gcd(ll a, ll b){
if (a == 0)
    return b;
return gcd(b % a, a);
}
ll lcm(ll a, ll b)
{
return (a*b)/gcd(a, b);
}
struct tt{
    ll a;
    ll b;
    ll c;
    ll d;
};
ll arr[1000009];
tt tree[5000000];
ll lazy[5000000];
void change(ll node){
    ll a=tree[node].a,b=tree[node].b,c=tree[node].c,d=tree[node].d;
        tree[node].a=c;
        tree[node].c=a;
        tree[node].b=d;
        tree[node].d=b;

}
void trees(ll start,ll end,ll node){
    ll mid=start+(end-start)/2;
    if(start==end){
        if(arr[start-1]==4){
            tree[node].a=1;tree[node].b=0;tree[node].c=0,tree[node].d=0;
        }else{
            tree[node].a=0;tree[node].b=0;tree[node].c=1,tree[node].d=0;
        }
        return ;
    }
    trees(start,mid,2*node);
    trees(mid+1,end,2*node+1);
    tt L=tree[2*node];tt R=tree[2*node+1];
    tree[node].a=L.a+R.a;
    tree[node].c=L.c+R.c;
    tree[node].b=max(L.a+max(R.b,R.c),L.b+R.c);
    tree[node].d=max(L.c+max(R.a,R.d),L.d+R.a);
}
void update(ll start,ll end,ll node,ll l,ll r){
    if(start>r||end<l)
        return;
    if(lazy[node]!=0){
        change(2*node+1);change(2*node);
        lazy[node]=0;
        if(start!=end){
            lazy[2*node]++;
            lazy[2*node]%=2;
            lazy[2*node+1]++;
            lazy[2*node+1]%=2;
        }

    }
    ll mid=start+(end-start)/2;
    if(end<l||start>r)
        return;
    if(start>=l&&end<=r){
        ll a=tree[node].a,b=tree[node].b,c=tree[node].c,d=tree[node].d;
        tree[node].a=c;
        tree[node].c=a;
        tree[node].b=d;
        tree[node].d=b;
        lazy[node]^=1;
        return;

    }
        update(start,mid,2*node,l,r);
        update(mid+1,end,2*node+1,l,r);
        tt L=tree[2*node];tt R=tree[2*node+1];
        tree[node].a=L.a+R.a;
        tree[node].c=L.c+R.c;
        tree[node].b=max(L.a+max(R.b,R.c),L.b+R.c);
        tree[node].d=max(L.c+max(R.a,R.d),L.d+R.a);

}
int main(){
    IOS;
    ll n,m;
    cin>>n>>m;
    string str;
    string count="count";
    cin>>str;
    forn(i,n){
        arr[i]=str[i]-'0';
    }
    trees(1,n,1);
    //cout<<max(tree[1].a,max(tree[1].b,tree[1].c));

    ll l,r;
    forn(i,m){
        cin>>str;
        if(str==count)
            printf("%lld\n",max(tree[1].a,max(tree[1].b,tree[1].c)));
        else{
            scanf("%lld %lld",&l,&r);
            update(1,n,1,l,r);

        }
    }
}