#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,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(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].d=max(L.c+max(R.a,R.d),L.d+R.a);

}
int main(){
    IOS;
    int n,m;
    cin>>n>>m;

    string count="count";
    cin>>arr;
    string str;
    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>
using namespace std;
const int N = 1000001;
char c[N],order[10];
struct data
{
	int n4;
	int n7;
	int s47;
	int s74;
	int lazy;
}ST[N*4],zero;
struct data combine(struct data x,struct data y)
{
	struct data k;
	k.n4=x.n4+y.n4;
	k.n7=x.n7+y.n7;
	k.s47 = max(x.s47+y.n7,max(x.n4+y.s47,x.n4+y.n4));
	k.s74 = max(x.s74+y.n4,max(x.n7+y.s74,x.n7+y.n4));
	k.lazy=0;
	return k;
}
void construct(int pos,int begin,int end)
{
	if(begin==end)
	{
		ST[pos].s47=1;
		ST[pos].s74=1;
		if(c[begin-1]=='4')
		{
			ST[pos].n4=1;
			ST[pos].n7=0;
		}
		else
		{
			ST[pos].n4=0;
			ST[pos].n7=1;
		}
		return;
	}
	int mid=(begin+end)/2;
	construct(pos*2,begin,mid);
	construct(pos*2+1,mid+1,end);
	ST[pos] = combine(ST[pos*2],ST[pos*2+1]);
}
void add(int pos,int begin,int end)
{
	if(ST[pos].lazy%2==0)
	{
		ST[pos].lazy=0;
		return;
	}
	int temp = ST[pos].n4;
	ST[pos].n4=ST[pos].n7;
	ST[pos].n7=temp;
	temp=ST[pos].s47;
	ST[pos].s47=ST[pos].s74;
	ST[pos].s74=temp;
	ST[pos*2].lazy = (ST[pos*2].lazy+1)%2;
	ST[pos*2+1].lazy = (ST[pos*2+1].lazy+1)%2;
	ST[pos].lazy=0;
}
void update(int pos,int begin,int end,int l,int r)
{
	add(pos,begin,end);
	if(begin>r||end<l)		return;
	if(begin>=l&&end<=r)
	{
		ST[pos].lazy+=1;
		add(pos,begin,end);
		return;
	}
	int mid=(begin+end)/2;
	update(pos*2,begin,mid,l,r);
	update(pos*2+1,mid+1,end,l,r);
	ST[pos] = combine(ST[pos*2],ST[pos*2+1]);
}
struct data find(int pos,int begin,int end,int l,int r)
{
	add(pos,begin,end);
	if(begin>r||end<l)		return zero;
	if(begin>=l&&end<=r)	return ST[pos];
	int mid=(begin+end)/2;
	return combine(find(pos*2,begin,mid,l,r) , find(pos*2+1,mid+1,end,l,r));
}
void print(int n)
{
	int i;
	for(i=1;i<2*n;++i)
	{
		printf("ST %d:%d %d %d %d %d\n",i,ST[i].n4,ST[i].n7,ST[i].s47,ST[i].s74,ST[i].lazy);
	}
}
int main()
{
	int i,n,m,x,y;
	scanf("%d %d",&n,&m);
	scanf("%s",c);
	for(i=1;i<=4*n;++i)		ST[i].lazy=0;
	construct(1,1,n);
	zero.lazy=0;
	zero.n4=0;
	zero.n7=0;
	zero.s47=0;
	zero.s74=0;
	for(i=1;i<=m;++i)
	{
		scanf("%s",order);
		if(order[0]=='s')
		{
			scanf("%d %d",&x,&y);
			update(1,1,n,x,y);
		}
		if(order[0]=='c')
		{
			printf("%d\n",find(1,1,n,1,n).s47);
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1000001;
char c[N],order[10];
struct data
{
	int n4;
	int n7;
	int s47;
	int s74;
	int lazy;
}ST[N*4],zero;
struct data combine(struct data x,struct data y)
{
	struct data k;
	k.n4=x.n4+y.n4;
	k.n7=x.n7+y.n7;
	k.s47 = max(x.s47+y.n7,max(x.n4+y.s47,x.n4+y.n4));
	k.s74 = max(x.s74+y.n4,max(x.n7+y.s74,x.n7+y.n4));
	k.lazy=0;
	return k;
}
void construct(int pos,int begin,int end)
{
	if(begin==end)
	{
		ST[pos].s47=1;
		ST[pos].s74=1;
		if(c[begin-1]=='4')
		{
			ST[pos].n4=1;
			ST[pos].n7=0;
		}
		else
		{
			ST[pos].n4=0;
			ST[pos].n7=1;
		}
		return;
	}
	int mid=(begin+end)/2;
	construct(pos*2,begin,mid);
	construct(pos*2+1,mid+1,end);
	ST[pos] = combine(ST[pos*2],ST[pos*2+1]);
}
void add(int pos,int begin,int end)
{
	if(ST[pos].lazy%2==0)	return;
	int temp = ST[pos].n4;
	ST[pos].n4=ST[pos].n7;
	ST[pos].n7=temp;
	temp=ST[pos].s47;
	ST[pos].s47=ST[pos].s74;
	ST[pos].s74=temp;
	ST[pos*2].lazy = (ST[pos*2].lazy+1)%2;
	ST[pos*2+1].lazy = (ST[pos*2+1].lazy+1)%2;
	ST[pos].lazy=0;
}
void update(int pos,int begin,int end,int l,int r)
{
	add(pos,begin,end);
	if(begin>r||end<l)		return;
	if(begin>=l&&end<=r)
	{
		ST[pos].lazy+=1;
		add(pos,begin,end);
		return;
	}
	int mid=(begin+end)/2;
	update(pos*2,begin,mid,l,r);
	update(pos*2+1,mid+1,end,l,r);
	ST[pos] = combine(ST[pos*2],ST[pos*2+1]);
}
struct data find(int pos,int begin,int end,int l,int r)
{
	add(pos,begin,end);
	if(begin>r||end<l)		return zero;
	if(begin>=l&&end<=r)	return ST[pos];
	int mid=(begin+end)/2;
	return combine(find(pos*2,begin,mid,l,r) , find(pos*2+1,mid+1,end,l,r));
}
void print(int n)
{
	int i;
	for(i=1;i<2*n;++i)
	{
		printf("ST %d:%d %d %d %d %d\n",i,ST[i].n4,ST[i].n7,ST[i].s47,ST[i].s74,ST[i].lazy);
	}
}
int main()
{
	int i,n,m,x,y;
	scanf("%d %d",&n,&m);
	scanf("%s",c);
	for(i=1;i<=2*n;++i)		ST[i].lazy=0;
	construct(1,1,n);
//	print(n);
	zero.lazy=0;
	zero.n4=0;
	zero.n7=0;
	zero.s47=0;
	zero.s74=0;
	for(i=1;i<=m;++i)
	{
		scanf("%s",order);
		if(order[0]=='s')
		{
			scanf("%d %d",&x,&y);
			update(1,1,n,x,y);
//			print(n);
		}
		if(order[0]=='c')
		{
			printf("%d\n",find(1,1,n,1,n).s47);
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1000001;
char c[N],order[10];
struct data
{
	int n4;
	int n7;
	int s47;
	int s74;
	int lazy;
}ST[N*4],zero;
struct data combine(struct data x,struct data y)
{
	struct data k;
	k.n4=x.n4+y.n4;
	k.n7=x.n7+y.n7;
	k.s47 = max(x.s47+y.n7,max(x.n4+y.s47,x.n4+y.n4));
	k.s74 = max(x.s74+y.n4,max(x.n7+y.s74,x.n7+y.n4));
	k.lazy=0;
	return k;
}
void construct(int pos,int begin,int end)
{
	if(begin==end)
	{
		ST[pos].s47=1;
		ST[pos].s74=1;
		if(c[begin-1]=='4')
		{
			ST[pos].n4=1;
			ST[pos].n7=0;
		}
		else
		{
			ST[pos].n4=0;
			ST[pos].n7=1;
		}
		return;
	}
	int mid=(begin+end)/2;
	construct(pos*2,begin,mid);
	construct(pos*2+1,mid+1,end);
	ST[pos] = combine(ST[pos*2],ST[pos*2+1]);
}
void add(int pos,int begin,int end)
{
	if(ST[pos].lazy%2==0)
	{
		ST[pos].lazy=0;
		return;
	}
	int temp = ST[pos].n4;
	ST[pos].n4=ST[pos].n7;
	ST[pos].n7=temp;
	temp=ST[pos].s47;
	ST[pos].s47=ST[pos].s74;
	ST[pos].s74=temp;
	ST[pos*2].lazy = (ST[pos*2].lazy+1)%2;
	ST[pos*2+1].lazy = (ST[pos*2+1].lazy+1)%2;
	ST[pos].lazy=0;
}
void update(int pos,int begin,int end,int l,int r)
{
	add(pos,begin,end);
	if(begin>r||end<l)		return;
	if(begin>=l&&end<=r)
	{
		ST[pos].lazy+=1;
		add(pos,begin,end);
		return;
	}
	int mid=(begin+end)/2;
	update(pos*2,begin,mid,l,r);
	update(pos*2+1,mid+1,end,l,r);
	ST[pos] = combine(ST[pos*2],ST[pos*2+1]);
}
struct data find(int pos,int begin,int end,int l,int r)
{
	add(pos,begin,end);
	if(begin>r||end<l)		return zero;
	if(begin>=l&&end<=r)	return ST[pos];
	int mid=(begin+end)/2;
	return combine(find(pos*2,begin,mid,l,r) , find(pos*2+1,mid+1,end,l,r));
}
void print(int n)
{
	int i;
	for(i=1;i<2*n;++i)
	{
		printf("ST %d:%d %d %d %d %d\n",i,ST[i].n4,ST[i].n7,ST[i].s47,ST[i].s74,ST[i].lazy);
	}
}
int main()
{
	int i,n,m,x,y;
	scanf("%d %d",&n,&m);
	scanf("%s",c);
	for(i=1;i<=4*N;++i)		ST[i].lazy=0;
	construct(1,1,n);
	zero.lazy=0;
	zero.n4=0;
	zero.n7=0;
	zero.s47=0;
	zero.s74=0;
	for(i=1;i<=m;++i)
	{
		scanf("%s",order);
		if(order[0]=='s')
		{
			scanf("%d %d",&x,&y);
			update(1,1,n,x,y);
		}
		if(order[0]=='c')
		{
			printf("%d\n",find(1,1,n,1,n).s47);
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1000001;
char c[N],order[10];
struct data
{
	int n4;
	int n7;
	int s47;
	int s74;
	int lazy;
}ST[N*4],zero;
struct data combine(struct data x,struct data y)
{
	struct data k;
	k.n4=x.n4+y.n4;
	k.n7=x.n7+y.n7;
	k.s47 = max(x.s47+y.n7,max(x.n4+y.s47,x.n4+y.n4));
	k.s74 = max(x.s74+y.n4,max(x.n7+y.s74,x.n7+y.n4));
	k.lazy=0;
	return k;
}
void construct(int pos,int begin,int end)
{
	if(begin==end)
	{
		ST[pos].s47=1;
		ST[pos].s74=1;
		if(c[begin-1]=='4')
		{
			ST[pos].n4=1;
			ST[pos].n7=0;
		}
		else
		{
			ST[pos].n4=0;
			ST[pos].n7=1;
		}
		return;
	}
	int mid=(begin+end)/2;
	construct(pos*2,begin,mid);
	construct(pos*2+1,mid+1,end);
	ST[pos] = combine(ST[pos*2],ST[pos*2+1]);
}
void add(int pos,int begin,int end)
{
	if(ST[pos].lazy%2==0)	return;
	int temp = ST[pos].n4;
	ST[pos].n4=ST[pos].n7;
	ST[pos].n7=temp;
	temp=ST[pos].s47;
	ST[pos].s47=ST[pos].s74;
	ST[pos].s74=temp;
	ST[pos*2].lazy += 1;
	ST[pos*2+1].lazy += 1;
	ST[pos].lazy=0;
}
void update(int pos,int begin,int end,int l,int r)
{
	add(pos,begin,end);
	if(begin>r||end<l)		return;
	if(begin>=l&&end<=r)
	{
		ST[pos].lazy+=1;
		add(pos,begin,end);
		return;
	}
	int mid=(begin+end)/2;
	update(pos*2,begin,mid,l,r);
	update(pos*2+1,mid+1,end,l,r);
	ST[pos] = combine(ST[pos*2],ST[pos*2+1]);
}
struct data find(int pos,int begin,int end,int l,int r)
{
	add(pos,begin,end);
	if(begin>r||end<l)		return zero;
	if(begin>=l&&end<=r)	return ST[pos];
	int mid=(begin+end)/2;
	return combine(find(pos*2,begin,mid,l,r) , find(pos*2+1,mid+1,end,l,r));
}
void print(int n)
{
	int i;
	for(i=1;i<2*n;++i)
	{
		printf("ST %d:%d %d %d %d %d\n",i,ST[i].n4,ST[i].n7,ST[i].s47,ST[i].s74,ST[i].lazy);
	}
}
int main()
{
	int i,n,m,x,y;
	scanf("%d %d",&n,&m);
	scanf("%s",c);
	for(i=1;i<=2*n;++i)		ST[i].lazy=0;
	construct(1,1,n);
//	print(n);
	zero.lazy=0;
	zero.n4=0;
	zero.n7=0;
	zero.s47=0;
	zero.s74=0;
	for(i=1;i<=m;++i)
	{
		scanf("%s",order);
		if(order[0]=='s')
		{
			scanf("%d %d",&x,&y);
			update(1,1,n,x,y);
//			print(n);
		}
		if(order[0]=='c')
		{
			printf("%d\n",find(1,1,n,1,n).s47);
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1000001;
char c[N],order[10];
struct data
{
	int n4;
	int n7;
	int s47;
	int s74;
	int lazy;
}ST[N*4+1],zero;
struct data combine(struct data x,struct data y)
{
	struct data k;
	k.n4=x.n4+y.n4;
	k.n7=x.n7+y.n7;
	k.s47 = max(x.s47+y.n7,max(x.n4+y.s47,x.n4+y.n4));
	k.s74 = max(x.s74+y.n4,max(x.n7+y.s74,x.n7+y.n4));
	k.lazy=0;
	return k;
}
void construct(int pos,int begin,int end)
{
	if(begin==end)
	{
		ST[pos].s47=1;
		ST[pos].s74=1;
		if(c[begin-1]=='4')
		{
			ST[pos].n4=1;
			ST[pos].n7=0;
		}
		else
		{
			ST[pos].n4=0;
			ST[pos].n7=1;
		}
		return;
	}
	int mid=(begin+end)/2;
	construct(pos*2,begin,mid);
	construct(pos*2+1,mid+1,end);
	ST[pos] = combine(ST[pos*2],ST[pos*2+1]);
}
void add(int pos,int begin,int end)
{
	if(ST[pos].lazy%2==0)
	{
		ST[pos].lazy=0;
		return;
	}
	int temp = ST[pos].n4;
	ST[pos].n4=ST[pos].n7;
	ST[pos].n7=temp;
	temp=ST[pos].s47;
	ST[pos].s47=ST[pos].s74;
	ST[pos].s74=temp;
	if(begin!=end)
	{
		ST[pos*2].lazy = (ST[pos*2].lazy+1)%2;
		ST[pos*2+1].lazy = (ST[pos*2+1].lazy+1)%2;
	}
	ST[pos].lazy=0;
}
void update(int pos,int begin,int end,int l,int r)
{
	add(pos,begin,end);
	if(begin>r||end<l)		return;
	if(begin>=l&&end<=r)
	{
		ST[pos].lazy+=1;
		add(pos,begin,end);
		return;
	}
	int mid=(begin+end)/2;
	update(pos*2,begin,mid,l,r);
	update(pos*2+1,mid+1,end,l,r);
	ST[pos] = combine(ST[pos*2],ST[pos*2+1]);
}
struct data find(int pos,int begin,int end,int l,int r)
{
	add(pos,begin,end);
	if(begin>r||end<l)		return zero;
	if(begin>=l&&end<=r)	return ST[pos];
	int mid=(begin+end)/2;
	return combine(find(pos*2,begin,mid,l,r) , find(pos*2+1,mid+1,end,l,r));
}
void print(int n)
{
	int i;
	for(i=1;i<2*n;++i)
	{
		printf("ST %d:%d %d %d %d %d\n",i,ST[i].n4,ST[i].n7,ST[i].s47,ST[i].s74,ST[i].lazy);
	}
}
int main()
{
	int i,n,m,x,y;
	scanf("%d %d",&n,&m);
	scanf("%s",c);
	for(i=1;i<=4*N;++i)		ST[i].lazy=0;
	construct(1,1,n);
	zero.lazy=0;
	zero.n4=0;
	zero.n7=0;
	zero.s47=0;
	zero.s74=0;
	for(i=1;i<=m;++i)
	{
		scanf("%s",order);
		if(order[0]=='s')
		{
			scanf("%d %d",&x,&y);
			update(1,1,n,x,y);
		}
		if(order[0]=='c')
		{
			printf("%d\n",find(1,1,n,1,n).s47);
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1000001;
char c[N],order[10];
struct data
{
	int n4;
	int n7;
	int s47;
	int s74;
	int lazy;
}ST[N*4+1],zero;
struct data combine(struct data x,struct data y)
{
	struct data k;
	k.n4=x.n4+y.n4;
	k.n7=x.n7+y.n7;
	k.s47 = max(x.s47+y.n7,max(x.n4+y.s47,x.n4+y.n4));
	k.s74 = max(x.s74+y.n4,max(x.n7+y.s74,x.n7+y.n4));
	k.lazy=0;
	return k;
}
void construct(int pos,int begin,int end)
{
	if(begin==end)
	{
		ST[pos].s47=1;
		ST[pos].s74=1;
		if(c[begin-1]=='4')
		{
			ST[pos].n4=1;
			ST[pos].n7=0;
		}
		else
		{
			ST[pos].n4=0;
			ST[pos].n7=1;
		}
		return;
	}
	int mid=(begin+end)/2;
	construct(pos*2,begin,mid);
	construct(pos*2+1,mid+1,end);
	ST[pos] = combine(ST[pos*2],ST[pos*2+1]);
}
void add(int pos,int begin,int end)
{
	if(ST[pos].lazy%2==0)
	{
		ST[pos].lazy=0;
		return;
	}
	int temp = ST[pos].n4;
	ST[pos].n4=ST[pos].n7;
	ST[pos].n7=temp;
	temp=ST[pos].s47;
	ST[pos].s47=ST[pos].s74;
	ST[pos].s74=temp;
	ST[pos*2].lazy = (ST[pos*2].lazy+1)%2;
	ST[pos*2+1].lazy = (ST[pos*2+1].lazy+1)%2;
	ST[pos].lazy=0;
}
void update(int pos,int begin,int end,int l,int r)
{
	add(pos,begin,end);
	if(begin>r||end<l)		return;
	if(begin>=l&&end<=r)
	{
		ST[pos].lazy+=1;
		add(pos,begin,end);
		return;
	}
	int mid=(begin+end)/2;
	update(pos*2,begin,mid,l,r);
	update(pos*2+1,mid+1,end,l,r);
	ST[pos] = combine(ST[pos*2],ST[pos*2+1]);
}
struct data find(int pos,int begin,int end,int l,int r)
{
	add(pos,begin,end);
	if(begin>r||end<l)		return zero;
	if(begin>=l&&end<=r)	return ST[pos];
	int mid=(begin+end)/2;
	return combine(find(pos*2,begin,mid,l,r) , find(pos*2+1,mid+1,end,l,r));
}
void print(int n)
{
	int i;
	for(i=1;i<2*n;++i)
	{
		printf("ST %d:%d %d %d %d %d\n",i,ST[i].n4,ST[i].n7,ST[i].s47,ST[i].s74,ST[i].lazy);
	}
}
int main()
{
	int i,n,m,x,y;
	scanf("%d %d",&n,&m);
	scanf("%s",c);
	for(i=1;i<=4*N;++i)		ST[i].lazy=0;
	construct(1,1,n);
	zero.lazy=0;
	zero.n4=0;
	zero.n7=0;
	zero.s47=0;
	zero.s74=0;
	for(i=1;i<=m;++i)
	{
		scanf("%s",order);
		if(order[0]=='s')
		{
			scanf("%d %d",&x,&y);
			update(1,1,n,x,y);
		}
		if(order[0]=='c')
		{
			printf("%d\n",find(1,1,n,1,n).s47);
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1000001;
char c[N],order[10];
struct data
{
	int n4;
	int n7;
	int s47;
	int s74;
	int lazy;
}ST[N*4],zero;
struct data combine(struct data x,struct data y)
{
	struct data k;
	k.n4=x.n4+y.n4;
	k.n7=x.n7+y.n7;
	k.s47 = max(x.s47+y.n7,max(x.n4+y.s47,x.n4+y.n4));
	k.s74 = max(x.s74+y.n4,max(x.n7+y.s74,x.n7+y.n4));
	k.lazy=0;
	return k;
}
void construct(int pos,int begin,int end)
{
	if(begin==end)
	{
		ST[pos].s47=1;
		ST[pos].s74=1;
		if(c[begin-1]=='4')
		{
			ST[pos].n4=1;
			ST[pos].n7=0;
		}
		else
		{
			ST[pos].n4=0;
			ST[pos].n7=1;
		}
		return;
	}
	int mid=(begin+end)/2;
	construct(pos*2,begin,mid);
	construct(pos*2+1,mid+1,end);
	ST[pos] = combine(ST[pos*2],ST[pos*2+1]);
}
void add(int pos,int begin,int end)
{
	if(ST[pos].lazy%2==0)	return;
	int temp = ST[pos].n4;
	ST[pos].n4=ST[pos].n7;
	ST[pos].n7=temp;
	temp=ST[pos].s47;
	ST[pos].s47=ST[pos].s74;
	ST[pos].s74=temp;
	ST[pos*2].lazy += 1;
	ST[pos*2+1].lazy += 1;
	ST[pos].lazy=0;
}
void update(int pos,int begin,int end,int l,int r)
{
	add(pos,begin,end);
	if(begin>r||end<l)		return;
	if(begin>=l&&end<=r)
	{
		ST[pos].lazy+=1;
		add(pos,begin,end);
		return;
	}
	int mid=(begin+end)/2;
	update(pos*2,begin,mid,l,r);
	update(pos*2+1,mid+1,end,l,r);
	ST[pos] = combine(ST[pos*2],ST[pos*2+1]);
}
data find(int pos,int begin,int end,int l,int r)
{
	add(pos,begin,end);
	if(begin>r||end<l)		return zero;
	if(begin>=l&&end<=r)	return ST[pos];
	int mid=(begin+end)/2;
	return combine(find(pos*2,begin,mid,l,r) , find(pos*2+1,mid+1,end,l,r));
}
void print(int n)
{
	int i;
	for(i=1;i<2*n;++i)
	{
		printf("ST %d:%d %d %d %d %d\n",i,ST[i].n4,ST[i].n7,ST[i].s47,ST[i].s74,ST[i].lazy);
	}
}
int main()
{
	int i,n,m,x,y;
	scanf("%d %d",&n,&m);
	scanf("%s",c);
	for(i=1;i<=2*n;++i)		ST[i].lazy=0;
	construct(1,1,n);
//	print(n);
	zero.lazy=0;
	zero.n4=0;
	zero.n7=0;
	zero.s47=0;
	zero.s74=0;
	for(i=1;i<=m;++i)
	{
		scanf("%s",order);
		if(order[0]=='s')
		{
			scanf("%d %d",&x,&y);
			update(1,1,n,x,y);
//			print(n);
		}
		if(order[0]=='c')
		{
			printf("%d\n",find(1,1,n,1,n).s47);
		}
	}
}


#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define hell 998244353
#define mp make_pair
#define all(x) x.begin(),x.end()
#define pb push_back
using namespace std;
ll n,m;
string s;
struct node
{
	ll cnt4,cnt7,inc,dec;
};
node tree[4000005];
ll lazy[4000005];
void build(ll si,ll ss,ll se)
{
	if(ss==se)
	{
		tree[si].cnt4=0;
		tree[si].cnt7=0;
		tree[si].inc=0;
		tree[si].dec=0;
		if(s[ss]=='4')
			tree[si].cnt4=1;
		else
			tree[si].cnt7=1;
		return;
	}
	ll mid=(ss+se)/2;
	build(si*2+1,ss,mid);
	build(si*2+2,mid+1,se);
	tree[si].cnt4=tree[si*2+1].cnt4+tree[si*2+2].cnt4;
	tree[si].cnt7=tree[si*2+1].cnt7+tree[si*2+2].cnt7;
	tree[si].inc=max(tree[si*2+1].inc,max(tree[si*2+2].inc,tree[si*2+1].cnt4+tree[si*2+2].cnt7));
	tree[si].inc=max(tree[si].inc,max(tree[si*2+1].inc+tree[si*2+2].cnt7,tree[si*2+1].cnt4+tree[si*2+2].inc));
	tree[si].dec=max(tree[si*2+1].dec,max(tree[si*2+2].dec,tree[si*2+1].cnt7+tree[si*2+2].cnt4));
	tree[si].dec=max(tree[si].dec,max(tree[si*2+1].dec+tree[si*2+2].cnt4,tree[si*2+1].cnt7+tree[si*2+2].dec));
}
void update(ll si,ll ss,ll se,ll qs,ll qe)
{
	if(lazy[si])
	{
		swap(tree[si].cnt4,tree[si].cnt7);
		swap(tree[si].inc,tree[si].dec);
		lazy[si]=0;
		if(ss!=se)
		{
			lazy[si*2+1]=1-lazy[si*2+1];
			lazy[si*2+2]=1-lazy[si*2+2];
		}
	}
	if(qe<ss||qs>se)
		return;
	if(ss>=qs && se<=qe)
	{
		swap(tree[si].cnt4,tree[si].cnt7);
		swap(tree[si].inc,tree[si].dec);
		if(ss!=se)
		{
			lazy[si*2+1]=1-lazy[si*2+1];
			lazy[si*2+2]=1-lazy[si*2+2];
		}
		return ;
	}
	ll mid=(ss+se)/2;
	update(si*2+1,ss,mid,qs,qe);
	update(si*2+2,mid+1,se,qs,qe);
	tree[si].cnt4=tree[si*2+1].cnt4+tree[si*2+2].cnt4;
	tree[si].cnt7=tree[si*2+1].cnt7+tree[si*2+2].cnt7;
	tree[si].inc=max(tree[si*2+1].inc,max(tree[si*2+2].inc,tree[si*2+1].cnt4+tree[si*2+2].cnt7));
	tree[si].inc=max(tree[si].inc,max(tree[si*2+1].inc+tree[si*2+2].cnt7,tree[si*2+1].cnt4+tree[si*2+2].inc));
	tree[si].dec=max(tree[si*2+1].dec,max(tree[si*2+2].dec,tree[si*2+1].cnt7+tree[si*2+2].cnt4));
	tree[si].dec=max(tree[si].dec,max(tree[si*2+1].dec+tree[si*2+2].cnt4,tree[si*2+1].cnt7+tree[si*2+2].dec));

}
int main()
{
	cin>>n>>m;
 	cin>>s;
 	build(0,0,n-1);

	while(m--)
	{
		string t;
		cin>>t;
		if(t=="count")
		{
			cout<<tree[0].inc<<"\n";
		}
		else
		{
			ll l,r;
			cin>>l>>r;
			l--;r--;
			update(0,0,n-1,l,r);
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define hell 998244353
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mp make_pair
#define all(x) x.begin(),x.end()
#define pb push_back
using namespace std;
ll n,m;
string s;
struct node
{
	ll cnt4,cnt7,inc,dec;
};
node tree[4000005];
ll lazy[4000005];
void build(ll si,ll ss,ll se)
{
	if(ss==se)
	{
		tree[si].cnt4=0;
		tree[si].cnt7=0;
		tree[si].inc=0;
		tree[si].dec=0;
		if(s[ss]=='4')
			tree[si].cnt4=1;
		else
			tree[si].cnt7=1;
		return;
	}
	ll mid=(ss+se)/2;
	build(si*2+1,ss,mid);
	build(si*2+2,mid+1,se);
	tree[si].cnt4=tree[si*2+1].cnt4+tree[si*2+2].cnt4;
	tree[si].cnt7=tree[si*2+1].cnt7+tree[si*2+2].cnt7;
	tree[si].inc=max(tree[si*2+1].inc,max(tree[si*2+2].inc,tree[si*2+1].cnt4+tree[si*2+2].cnt7));
	tree[si].inc=max(tree[si].inc,max(tree[si*2+1].inc+tree[si*2+2].cnt7,tree[si*2+1].cnt4+tree[si*2+2].inc));
	tree[si].dec=max(tree[si*2+1].dec,max(tree[si*2+2].dec,tree[si*2+1].cnt7+tree[si*2+2].cnt4));
	tree[si].dec=max(tree[si].dec,max(tree[si*2+1].dec+tree[si*2+2].cnt4,tree[si*2+1].cnt7+tree[si*2+2].dec));
}
void update(ll si,ll ss,ll se,ll qs,ll qe)
{
	if(lazy[si])
	{
		swap(tree[si].cnt4,tree[si].cnt7);
		swap(tree[si].inc,tree[si].dec);
		lazy[si]=0;
		if(ss!=se)
		{
			lazy[si*2+1]=1-lazy[si*2+1];
			lazy[si*2+2]=1-lazy[si*2+2];
		}
	}
	if(qe<ss||qs>se)
		return;
	if(ss>=qs && se<=qe)
	{
		swap(tree[si].cnt4,tree[si].cnt7);
		swap(tree[si].inc,tree[si].dec);
		if(ss!=se)
		{
			lazy[si*2+1]=1-lazy[si*2+1];
			lazy[si*2+2]=1-lazy[si*2+2];
		}
		return ;
	}
	ll mid=(ss+se)/2;
	update(si*2+1,ss,mid,qs,qe);
	update(si*2+2,mid+1,se,qs,qe);
	tree[si].cnt4=tree[si*2+1].cnt4+tree[si*2+2].cnt4;
	tree[si].cnt7=tree[si*2+1].cnt7+tree[si*2+2].cnt7;
	tree[si].inc=max(tree[si*2+1].inc,max(tree[si*2+2].inc,tree[si*2+1].cnt4+tree[si*2+2].cnt7));
	tree[si].inc=max(tree[si].inc,max(tree[si*2+1].inc+tree[si*2+2].cnt7,tree[si*2+1].cnt4+tree[si*2+2].inc));
	tree[si].dec=max(tree[si*2+1].dec,max(tree[si*2+2].dec,tree[si*2+1].cnt7+tree[si*2+2].cnt4));
	tree[si].dec=max(tree[si].dec,max(tree[si*2+1].dec+tree[si*2+2].cnt4,tree[si*2+1].cnt7+tree[si*2+2].dec));

}
int main()
{
	IOS
	cin>>n>>m;
 	cin>>s;
 	build(0,0,n-1);

	while(m--)
	{
		string t;
		cin>>t;
		if(t=="count")
		{
			cout<<max(tree[0].inc,max(tree[0].cnt4,tree[0].cnt7))<<"\n";
		}
		else
		{
			ll l,r;
			cin>>l>>r;
			l--;r--;
			update(0,0,n-1,l,r);
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define hell 998244353
#define mp make_pair
#define all(x) x.begin(),x.end()
#define pb push_back
using namespace std;
ll n,m;
string s;
struct node
{
	ll cnt4,cnt7,inc,dec;
};
node tree[4000005];
ll lazy[4000005];
void build(ll si,ll ss,ll se)
{
	if(ss==se)
	{
		tree[si].cnt4=0;
		tree[si].cnt7=0;
		tree[si].inc=0;
		tree[si].dec=0;
		if(s[ss]=='4')
			tree[si].cnt4=1;
		else
			tree[si].cnt7=1;
		return;
	}
	ll mid=(ss+se)/2;
	build(si*2+1,ss,mid);
	build(si*2+2,mid+1,se);
	tree[si].cnt4=tree[si*2+1].cnt4+tree[si*2+2].cnt4;
	tree[si].cnt7=tree[si*2+1].cnt7+tree[si*2+2].cnt7;
	tree[si].inc=max(tree[si*2+1].inc,max(tree[si*2+2].inc,tree[si*2+1].cnt4+tree[si*2+2].cnt7));
	tree[si].inc=max(tree[si].inc,max(tree[si*2+1].cnt7,tree[si*2+2].cnt4));
	tree[si].dec=max(tree[si*2+1].dec,max(tree[si*2+2].dec,tree[si*2+1].cnt7+tree[si*2+2].cnt4));
	tree[si].dec=max(tree[si].dec,max(tree[si*2+1].cnt4,tree[si*2+2].cnt7));
}
void update(ll si,ll ss,ll se,ll qs,ll qe)
{
	if(lazy[si])
	{
		swap(tree[si].cnt4,tree[si].cnt7);
		swap(tree[si].inc,tree[si].dec);
		lazy[si]=0;
		if(ss!=se)
		{
			lazy[si*2+1]=1;
			lazy[si*2+1]=1;
		}
	}
	if(qe<ss||qs>se)
		return;
	if(ss>=qs && se<=qe)
	{
		swap(tree[si].cnt4,tree[si].cnt7);
		swap(tree[si].inc,tree[si].dec);
		if(ss!=se)
		{
			lazy[si*2+1]=1;
			lazy[si*2+1]=1;
		}
		return ;
	}
	ll mid=(ss+se)/2;
	update(si*2+1,ss,mid,qs,qe);
	update(si*2+2,mid+1,se,qs,qe);
	tree[si].cnt4=tree[si*2+1].cnt4+tree[si*2+2].cnt4;
	tree[si].cnt7=tree[si*2+1].cnt7+tree[si*2+2].cnt7;
	tree[si].inc=max(tree[si*2+1].inc,max(tree[si*2+2].inc,tree[si*2+1].cnt4+tree[si*2+2].cnt7));
	tree[si].inc=max(tree[si].inc,max(tree[si*2+1].cnt7,tree[si*2+2].cnt4));
	tree[si].dec=max(tree[si*2+1].dec,max(tree[si*2+2].dec,tree[si*2+1].cnt7+tree[si*2+2].cnt4));
	tree[si].dec=max(tree[si].dec,max(tree[si*2+1].cnt4,tree[si*2+2].cnt7));

}
int main()
{
	cin>>n>>m;
 	cin>>s;
 	build(0,0,n-1);

	while(m--)
	{
		string t;
		cin>>t;
		if(t=="count")
			cout<<tree[0].inc<<"\n";
		else
		{
			ll l,r;
			cin>>l>>r;
			l--;r--;
			update(0,0,n-1,l,r);
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define hell 998244353
#define mp make_pair
#define all(x) x.begin(),x.end()
#define pb push_back
using namespace std;
ll n,m;
string s;
struct node
{
	ll cnt4,cnt7,inc,dec;
};
node tree[4000005];
ll lazy[4000005];
void build(ll si,ll ss,ll se)
{
	if(ss==se)
	{
		tree[si].cnt4=0;
		tree[si].cnt7=0;
		tree[si].inc=0;
		tree[si].dec=0;
		if(s[ss]=='4')
			tree[si].cnt4=1;
		else
			tree[si].cnt7=1;
		return;
	}
	ll mid=(ss+se)/2;
	build(si*2+1,ss,mid);
	build(si*2+2,mid+1,se);
	tree[si].cnt4=tree[si*2+1].cnt4+tree[si*2+2].cnt4;
	tree[si].cnt7=tree[si*2+1].cnt7+tree[si*2+2].cnt7;
	tree[si].inc=max(tree[si*2+1].inc,max(tree[si*2+2].inc,tree[si*2+1].cnt4+tree[si*2+2].cnt7));
	tree[si].inc=max(tree[si].inc,max(tree[si*2+1].inc+tree[si*2+2].cnt7,tree[si*2+1].cnt4+tree[si*2+2].inc));
	tree[si].dec=max(tree[si*2+1].dec,max(tree[si*2+2].dec,tree[si*2+1].cnt7+tree[si*2+2].cnt4));
	tree[si].dec=max(tree[si].dec,max(tree[si*2+1].dec+tree[si*2+2].cnt4,tree[si*2+1].cnt7+tree[si*2+2].dec));
}
void update(ll si,ll ss,ll se,ll qs,ll qe)
{
	if(lazy[si])
	{
		swap(tree[si].cnt4,tree[si].cnt7);
		swap(tree[si].inc,tree[si].dec);
		lazy[si]=0;
		if(ss!=se)
		{
			lazy[si*2+1]=1;
			lazy[si*2+2]=1;
		}
	}
	if(qe<ss||qs>se)
		return;
	if(ss>=qs && se<=qe)
	{
		swap(tree[si].cnt4,tree[si].cnt7);
		swap(tree[si].inc,tree[si].dec);
		if(ss!=se)
		{
			lazy[si*2+1]=1;
			lazy[si*2+2]=1;
		}
		return ;
	}
	ll mid=(ss+se)/2;
	update(si*2+1,ss,mid,qs,qe);
	update(si*2+2,mid+1,se,qs,qe);
	tree[si].cnt4=tree[si*2+1].cnt4+tree[si*2+2].cnt4;
	tree[si].cnt7=tree[si*2+1].cnt7+tree[si*2+2].cnt7;
	tree[si].inc=max(tree[si*2+1].inc,max(tree[si*2+2].inc,tree[si*2+1].cnt4+tree[si*2+2].cnt7));
	tree[si].inc=max(tree[si].inc,max(tree[si*2+1].inc+tree[si*2+2].cnt7,tree[si*2+1].cnt4+tree[si*2+2].inc));
	tree[si].dec=max(tree[si*2+1].dec,max(tree[si*2+2].dec,tree[si*2+1].cnt7+tree[si*2+2].cnt4));
	tree[si].dec=max(tree[si].dec,max(tree[si*2+1].dec+tree[si*2+2].cnt4,tree[si*2+1].cnt7+tree[si*2+2].dec));

}
int main()
{
	cin>>n>>m;
 	cin>>s;
 	build(0,0,n-1);

	while(m--)
	{
		string t;
		cin>>t;
		if(t=="count")
		{
			cout<<max(tree[0].inc,tree[0].cnt7)<<"\n";
		}
		else
		{
			ll l,r;
			cin>>l>>r;
			l--;r--;
			update(0,0,n-1,l,r);
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define hell 998244353
#define mp make_pair
#define all(x) x.begin(),x.end()
#define pb push_back
using namespace std;
ll n,m;
string s;
struct node
{
	ll cnt4,cnt7,inc,dec;
};
node tree[4000005];
ll lazy[4000005];
void build(ll si,ll ss,ll se)
{
	if(ss==se)
	{
		tree[si].cnt4=0;
		tree[si].cnt7=0;
		tree[si].inc=0;
		tree[si].dec=0;
		if(s[ss]=='4')
			tree[si].cnt4=1;
		else
			tree[si].cnt7=1;
		return;
	}
	ll mid=(ss+se)/2;
	build(si*2+1,ss,mid);
	build(si*2+2,mid+1,se);
	tree[si].cnt4=tree[si*2+1].cnt4+tree[si*2+2].cnt4;
	tree[si].cnt7=tree[si*2+1].cnt7+tree[si*2+2].cnt7;
	tree[si].inc=max(tree[si*2+1].inc,max(tree[si*2+2].inc,tree[si*2+1].cnt4+tree[si*2+2].cnt7));
	tree[si].inc=max(tree[si].inc,max(tree[si*2+1].inc+tree[si*2+2].cnt7,tree[si*2+1].cnt4+tree[si*2+2].inc));
	tree[si].dec=max(tree[si*2+1].dec,max(tree[si*2+2].dec,tree[si*2+1].cnt7+tree[si*2+2].cnt4));
	tree[si].dec=max(tree[si].dec,max(tree[si*2+1].dec+tree[si*2+2].cnt4,tree[si*2+1].cnt7+tree[si*2+2].dec));
}
void update(ll si,ll ss,ll se,ll qs,ll qe)
{
	if(lazy[si])
	{
		swap(tree[si].cnt4,tree[si].cnt7);
		swap(tree[si].inc,tree[si].dec);
		lazy[si]=0;
		if(ss!=se)
		{
			lazy[si*2+1]=1-lazy[si*2+1];
			lazy[si*2+2]=1-lazy[si*2+2];
		}
	}
	if(qe<ss||qs>se)
		return;
	if(ss>=qs && se<=qe)
	{
		swap(tree[si].cnt4,tree[si].cnt7);
		swap(tree[si].inc,tree[si].dec);
		if(ss!=se)
		{
			lazy[si*2+1]=1-lazy[si*2+1];
			lazy[si*2+2]=1-lazy[si*2+2];
		}
		return ;
	}
	ll mid=(ss+se)/2;
	update(si*2+1,ss,mid,qs,qe);
	update(si*2+2,mid+1,se,qs,qe);
	tree[si].cnt4=tree[si*2+1].cnt4+tree[si*2+2].cnt4;
	tree[si].cnt7=tree[si*2+1].cnt7+tree[si*2+2].cnt7;
	tree[si].inc=max(tree[si*2+1].inc,max(tree[si*2+2].inc,tree[si*2+1].cnt4+tree[si*2+2].cnt7));
	tree[si].inc=max(tree[si].inc,max(tree[si*2+1].inc+tree[si*2+2].cnt7,tree[si*2+1].cnt4+tree[si*2+2].inc));
	tree[si].dec=max(tree[si*2+1].dec,max(tree[si*2+2].dec,tree[si*2+1].cnt7+tree[si*2+2].cnt4));
	tree[si].dec=max(tree[si].dec,max(tree[si*2+1].dec+tree[si*2+2].cnt4,tree[si*2+1].cnt7+tree[si*2+2].dec));

}
int main()
{
	cin>>n>>m;
 	cin>>s;
 	build(0,0,n-1);

	while(m--)
	{
		string t;
		cin>>t;
		if(t=="count")
		{
			cout<<max(tree[0].inc,max(tree[0].cnt4,tree[0].cnt7))<<"\n";
		}
		else
		{
			ll l,r;
			cin>>l>>r;
			l--;r--;
			update(0,0,n-1,l,r);
		}
	}
	return 0;
}


#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("input.txt");ofstream out("output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int G = 1<<21, T = G/2;
int a,z,m[G][4], fl[G];
str t;

void upd(int v){
    if(v>=T) return;
    m[v][0] = m[v*2][0] + m[v*2+1][0];
    m[v][3] = m[v*2][3] + m[v*2+1][3];

    m[v][1] = max({m[v*2][0]+m[v*2+1][3], m[v*2][0]+m[v*2+1][1], m[v*2][1]+m[v*2+1][3]});
    m[v][2] = max({m[v*2][3]+m[v*2+1][0], m[v*2][3]+m[v*2+1][2], m[v*2][2]+m[v*2+1][0]});
}

void push(int v) {
    if(v>=T || !fl[v]) return;
    fl[v*2] ^= 1;
    fl[v*2+1] ^= 1;
    swap(m[v*2][0], m[v*2][3]);
    swap(m[v*2][1], m[v*2][2]);
    swap(m[v*2+1][0], m[v*2+1][3]);
    swap(m[v*2+1][1], m[v*2+1][2]);
    fl[v] = 0;
}

void go(int L, int R, int l, int r, int v){
    if(R<l || L>r) return;
    push(v);
    if(L<=l && r<=R){
        fl[v] ^= 1;
        swap(m[v][0], m[v][3]);
        swap(m[v][1], m[v][2]);
        return;
    }
    int md = (l+r)/2;
    go(L,R,l,md,v*2);
    go(L,R,md+1,r,v*2+1);
    upd(v);
}

int main() {
    fast;
    memset(m, 0, sizeof(m));
    memset(fl, 0, sizeof(fl));
    cin>>a>>z>>t;
    for(int q=0; q<a; q++){
        if(t[q]=='4'){
            m[T+q][0] = 1;
        }
        else{
            m[T+q][3] = 1;
        }
    }
    for(int q=T-1; q; q--){
        upd(q);
    }
    for(; z--;){
        str XYU; cin>>XYU;
        if(XYU=="count") cout<<max({m[1][0], m[1][1], m[1][3]})<<"\n";
        else{
            int l,r; cin>>l>>r;
            go(l, r, 1, T, 1);
        }
    }
}


#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("input.txt");ofstream out("output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int G = 1<<21, T = G/2;
int a,z,m[G][4], fl[G];
str t;

void upd(int v){
    if(v>=T) return;
    m[v][0] = m[v*2][0] + m[v*2+1][0];
    m[v][3] = m[v*2][3] + m[v*2+1][3];

    m[v][1] = max({m[v*2][0]+m[v*2+1][3], m[v*2][0]+m[v*2+1][1], m[v*2][1]+m[v*2+1][3]});
    m[v][2] = max({m[v*2][3]+m[v*2+1][0], m[v*2][3]+m[v*2+1][2], m[v*2][2]+m[v*2+1][0]});
}

void push(int v) {
    if(v>=T || !fl[v]) return;
    fl[v*2] ^= 1;
    fl[v*2+1] ^= 1;
    swap(m[v*2][0], m[v*2][3]);
    swap(m[v*2][1], m[v*2][2]);
    swap(m[v*2+1][0], m[v*2+1][3]);
    swap(m[v*2+1][1], m[v*2+1][2]);
    fl[v] = 0;
}

void go(int L, int R, int l, int r, int v){
    if(R<l || L>r) return;
    push(v);
    if(L<=l && r<=R){
        fl[v] ^= 1;
        swap(m[v][0], m[v][3]);
        swap(m[v][1], m[v][2]);
        return;
    }
    int md = (l+r)/2;
    go(L,R,l,md,v*2);
    go(L,R,md+1,r,v*2+1);
    upd(v);
}

int main() {
    fast;
    memset(m, 0, sizeof(m));
    memset(fl, 0, sizeof(fl));
    cin>>a>>z>>t;
    for(int q=0; q<a; q++){
        if(t[q]=='4'){
            m[T+q][0] = 1;
        }
        else{
            m[T+q][3] = 1;
        }
    }
    for(int q=T-1; q; q--){
        upd(q);
    }
    for(; z--;){
        str XYU; cin>>XYU;
        if(XYU=="count") cout<<max({m[1][0], m[1][1], m[1][3]})<<endl;
        else{
            int l,r; cin>>l>>r;
            go(l, r, 1, T, 1);
        }
    }
}


#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("input.txt");ofstream out("output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int G = 1<<21, T = G/2;
int a,z,m[G][4], fl[G];
str t;

void upd(int v){
    if(v>=T) return;
    m[v][0] = m[v*2][0] + m[v*2+1][0];
    m[v][3] = m[v*2][3] + m[v*2+1][3];

    m[v][1] = max({m[v*2][0]+m[v*2+1][3], m[v*2][0]+m[v*2+1][1], m[v*2][1]+m[v*2+1][3]});
    m[v][2] = max({m[v*2][3]+m[v*2+1][0], m[v*2][3]+m[v*2+1][2], m[v*2][2]+m[v*2+1][0]});
}

void push(int v) {
    if(v>=T || !fl[v]) return;
    fl[v*2] ^= 1;
    fl[v*2+1] ^= 1;
    reverse(m[v*2], m[v*2]+4);
    reverse(m[v*2+1], m[v*2+1]+4);
    fl[v] = 0;
}

void go(int L, int R, int l, int r, int v){
    if(R<l || L>r) return;
    push(v);
    if(L<=l && r<=R){
        fl[v] ^= 1;
        reverse(m[v], m[v]+4);
        return;
    }
    int md = (l+r)/2;
    go(L,R,l,md,v*2);
    go(L,R,md+1,r,v*2+1);
    upd(v);
}

int main() {
    fast;
    memset(m, 0, sizeof(m));
    memset(fl, 0, sizeof(fl));
    cin>>a>>z>>t;
    for(int q=0; q<a; q++) m[T+q][t[q]-'4'] = 1;
    for(int q=T-1; q; q--) upd(q);
    for(; z--;){
        str XYU; cin>>XYU;
        if(XYU=="count") cout<<max({m[1][0], m[1][1], m[1][3]})<<"\n";
        else{
            int l,r; cin>>l>>r;
            go(l, r, 1, T, 1);
        }
    }
}


/**         (buri nazar wale tera muh kala 😑)
 *
 * @Author   : rudraksh
 * @Created  : Wednesday, May 27th 2020, 10:11:16 pm
 * @Email    : rudrakshk@iitbhilai.ac.in
 *
 *   Always give 100% — unless you’re donating blood.
 */

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

typedef long long int ll;
typedef unsigned long long ull;
typedef double db;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef map<int,int> MI;
typedef vector<VI> VVI;
typedef pair<int,PI> PIP;

#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define mp make_pair
#define repa(i,a,n) for(ll i=a;i<n;i++)
#define rep(i,n) for(ll i=0;i<n;i++)
#define pera(i,a,n) for(ll i=a;i>=n;i--)
#define per(i,n) for(ll i=n;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define loop(it,x) for(auto it=x.begin();it!=x.end();it++)
#define MS0(x) memset((x), 0, sizeof((x)))
#define MS1(x) memset((x), -1, sizeof((x)))
#define CP(dst,src) memcpy(dst, src, sizeof(src));
#define SZ(x) ((ll)(x).size())
#define TIME    cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";

const ll mod=1e9+7;
const double pi=acos(-1);

ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
ll power(ll a,ll b,ll p) //log(b)
{
    if(b==0) return 1;
    ll c = power(a,b/2,p);
    if(b%2==0) return (c*c)%p;
    else return (((c*c)%p)*a)%p;
}
ll inv(ll n, ll p){ return power(n,p-2, p); }
bool isPrime(ll n) {
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (ll i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
            return false;
    return true;
}

const int maxn=1000001;
int n;
int h = sizeof(int) * 8 - __builtin_clz(n);
int t[2*maxn][4];
bool lazy[2*maxn];

void apply(int p, bool val)
{
    swap(t[p][0],t[p][1]);
    swap(t[p][2],t[p][3]);
    if(p<n) lazy[p] |= val;
}

void build(int i)
{
    while(i>1)
    {
        i>>=1;
        int c1=i*2;
        int c2=c1+1;
        t[i][0]=t[c1][0]+t[c2][0];
        t[i][1]=t[c1][1]+t[c2][1];
        t[i][2]=max({t[c1][2]+t[c2][1],t[c1][0]+t[c2][2],t[c1][0]+t[c2][1]});
        t[i][3]=max({t[c1][3]+t[c2][0],t[c1][1]+t[c2][3],t[c1][1]+t[c2][0]});
        if(lazy[i])
        {
            swap(t[i][0],t[i][1]);
            swap(t[i][2],t[i][3]);
        }
    }
}

void push(int p)
{
    for(int s=h;s>0;s--)
    {
        int i = p>>s;
        if (lazy[i])
        {
            apply(i<<1, lazy[i]);
            apply(i<<1|1, lazy[i]);
            lazy[i] = false;
        }
    }
}

void swtch(int l,int r)
{
    l+=n-1,r+=n;
    int l0=l,r0=r;
    while(l<r)
    {
        if(l&1) apply(l++,true);
        if(r&1) apply(--r,true);
        l>>=1,r>>=1;
    }
    build(l0);
    build(r0-1);
}

int query(int l, int r)
{
    l+=n-1,r+=n;
    push(l);
    push(r-1);
    int a[4],b[4];
    MS0(a);
    MS0(b);
    while(l<r)
    {
        if(l&1)
        {
            a[2] = max({a[0]+t[l][1],a[2]+t[l][1],a[0]+t[l][2]});
            a[3] = max({a[1]+t[l][0],a[3]+t[l][0],a[1]+t[l][3]});
            a[0] += t[l][0];
            a[1] += t[l][1];
            l+=1;
        }
        if(r&1)
        {
            r-=1;
            b[2] = max({b[1]+t[r][0],b[1]+t[r][2],b[2]+t[r][0]});
            b[3] = max({b[0]+t[r][1],b[0]+t[r][3],b[3]+t[r][1]});
            b[0] += t[r][0];
            b[1] += t[r][1];
        }
        l>>=1,r>>=1;
    }
    // cout<<l<<' '<<r<<'\n';
    // cout<<a[2]+b[1]<<' '<<a[0]+b[2]<<' '<<a[0]+b[1]<<'\n';
    return (1) ? max({a[2]+b[1],a[0]+b[2],a[0]+b[1]}) : a[2];
    // return a[2];
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int m;
    cin>>n>>m;
    char dig;
    rep(i,n)
    {
        cin>>dig;
        // cout<<dig<<endl;
        int x;
        (dig=='4') ? x=0:x=1;
        t[i+n][0]=x^1;
        t[i+n][1]=x^0;
        t[i+n][2]=t[i+n][3]=1;
    }
    pera(i,n-1,1)
    {
        int c1=i<<1;
        int c2=c1+1;
        t[i][0]=t[c1][0]+t[c2][0];
        t[i][1]=t[c1][1]+t[c2][1];
        t[i][2]=max({t[c1][2]+t[c2][1],t[c1][0]+t[c2][2],t[c1][0]+t[c2][1]});
        t[i][3]=max({t[c1][3]+t[c2][0],t[c1][1]+t[c2][3],t[c1][1]+t[c2][0]});
    }
    MS0(lazy);
    while(m--)
    {
        string s;
        cin>>s;
        // cout<<s<<endl;
        if(s=="count") cout<<query(1,n)<<'\n';
        else
        {
            int l,r;
            cin>>l>>r;
            swtch(l,r);
        }
    }
    // repa(i,1,2*n) cout<<t[i][0]<<' ';

    return 0;
}


/**         (buri nazar wale tera muh kala 😑)
 *
 * @Author   : rudraksh
 * @Created  : Wednesday, May 27th 2020, 10:24:31 pm
 * @Email    : rudrakshk@iitbhilai.ac.in
 *
 *   Always give 100% — unless you’re donating blood.
 */

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

typedef long long int ll;
typedef unsigned long long ull;
typedef double db;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef map<int,int> MI;
typedef vector<VI> VVI;
typedef pair<int,PI> PIP;

#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define mp make_pair
#define repa(i,a,n) for(ll i=a;i<n;i++)
#define rep(i,n) for(ll i=0;i<n;i++)
#define pera(i,a,n) for(ll i=a;i>=n;i--)
#define per(i,n) for(ll i=n;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define loop(it,x) for(auto it=x.begin();it!=x.end();it++)
#define MS0(x) memset((x), 0, sizeof((x)))
#define MS1(x) memset((x), -1, sizeof((x)))
#define CP(dst,src) memcpy(dst, src, sizeof(src));
#define SZ(x) ((ll)(x).size())
#define TIME    cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";

const ll mod=1e9+7;
const double pi=acos(-1);

ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
ll power(ll a,ll b,ll p) //log(b)
{
    if(b==0) return 1;
    ll c = power(a,b/2,p);
    if(b%2==0) return (c*c)%p;
    else return (((c*c)%p)*a)%p;
}
ll inv(ll n, ll p){ return power(n,p-2, p); }
bool isPrime(ll n) {
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (ll i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
            return false;
    return true;
}

const int maxn=1000001;
int n;
int h = sizeof(int) * 8 - __builtin_clz(n);
int t[2*maxn][4];
bool lazy[2*maxn];

void apply(int p)
{
    swap(t[p][0],t[p][1]);
    swap(t[p][2],t[p][3]);
    if(p<n) lazy[p] = !lazy[p];
}

void build(int i)
{
    while(i>1)
    {
        i>>=1;
        int c1=i*2;
        int c2=c1+1;
        t[i][0]=t[c1][0]+t[c2][0];
        t[i][1]=t[c1][1]+t[c2][1];
        t[i][2]=max({t[c1][2]+t[c2][1],t[c1][0]+t[c2][2],t[c1][0]+t[c2][1]});
        t[i][3]=max({t[c1][3]+t[c2][0],t[c1][1]+t[c2][3],t[c1][1]+t[c2][0]});
        if(lazy[i])
        {
            swap(t[i][0],t[i][1]);
            swap(t[i][2],t[i][3]);
        }
    }
}

void push(int p)
{
    for(int s=h;s>0;s--)
    {
        int i = p>>s;
        if (lazy[i])
        {
            apply(i<<1);
            apply(i<<1|1);
            lazy[i] = false;
        }
    }
}

void swtch(int l,int r)
{
    l+=n-1,r+=n;
    int l0=l,r0=r;
    while(l<r)
    {
        if(l&1) apply(l++);
        if(r&1) apply(--r);
        l>>=1,r>>=1;
    }
    build(l0);
    build(r0-1);
}

int query(int l, int r)
{
    l+=n-1,r+=n;
    push(l);
    push(r-1);
    int a[4],b[4];
    MS0(a);
    MS0(b);
    while(l<r)
    {
        if(l&1)
        {
            a[2] = max({a[0]+t[l][1],a[2]+t[l][1],a[0]+t[l][2]});
            a[3] = max({a[1]+t[l][0],a[3]+t[l][0],a[1]+t[l][3]});
            a[0] += t[l][0];
            a[1] += t[l][1];
            l+=1;
        }
        if(r&1)
        {
            r-=1;
            b[2] = max({b[1]+t[r][0],b[1]+t[r][2],b[2]+t[r][0]});
            b[3] = max({b[0]+t[r][1],b[0]+t[r][3],b[3]+t[r][1]});
            b[0] += t[r][0];
            b[1] += t[r][1];
        }
        l>>=1,r>>=1;
    }
    // cout<<l<<' '<<r<<'\n';
    // cout<<a[2]+b[1]<<' '<<a[0]+b[2]<<' '<<a[0]+b[1]<<'\n';
    return (1) ? max({a[2]+b[1],a[0]+b[2],a[0]+b[1]}) : a[2];
    // return a[2];
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int m;
    cin>>n>>m;
    char dig;
    rep(i,n)
    {
        cin>>dig;
        // cout<<dig<<endl;
        int x;
        (dig=='4') ? x=0:x=1;
        t[i+n][0]=x^1;
        t[i+n][1]=x^0;
        t[i+n][2]=t[i+n][3]=1;
    }
    pera(i,n-1,1)
    {
        int c1=i<<1;
        int c2=c1+1;
        t[i][0]=t[c1][0]+t[c2][0];
        t[i][1]=t[c1][1]+t[c2][1];
        t[i][2]=max({t[c1][2]+t[c2][1],t[c1][0]+t[c2][2],t[c1][0]+t[c2][1]});
        t[i][3]=max({t[c1][3]+t[c2][0],t[c1][1]+t[c2][3],t[c1][1]+t[c2][0]});
    }
    MS0(lazy);
    while(m--)
    {
        string s;
        cin>>s;
        // cout<<s<<endl;
        if(s=="count") cout<<query(1,n)<<endl;
        else
        {
            int l,r;
            cin>>l>>r;
            swtch(l,r);
        }
    }
    // repa(i,1,2*n) cout<<t[i][0]<<' ';

    return 0;
}


/**         (buri nazar wale tera muh kala 😑)
 *
 * @Author   : rudraksh
 * @Created  : Wednesday, May 27th 2020, 10:24:31 pm
 * @Email    : rudrakshk@iitbhilai.ac.in
 *
 *   Always give 100% — unless you’re donating blood.
 */

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

typedef long long int ll;
typedef unsigned long long ull;
typedef double db;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef map<int,int> MI;
typedef vector<VI> VVI;
typedef pair<int,PI> PIP;

#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define mp make_pair
#define repa(i,a,n) for(ll i=a;i<n;i++)
#define rep(i,n) for(ll i=0;i<n;i++)
#define pera(i,a,n) for(ll i=a;i>=n;i--)
#define per(i,n) for(ll i=n;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define loop(it,x) for(auto it=x.begin();it!=x.end();it++)
#define MS0(x) memset((x), 0, sizeof((x)))
#define MS1(x) memset((x), -1, sizeof((x)))
#define CP(dst,src) memcpy(dst, src, sizeof(src));
#define SZ(x) ((ll)(x).size())
#define TIME    cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";

const ll mod=1e9+7;
const double pi=acos(-1);

ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
ll power(ll a,ll b,ll p) //log(b)
{
    if(b==0) return 1;
    ll c = power(a,b/2,p);
    if(b%2==0) return (c*c)%p;
    else return (((c*c)%p)*a)%p;
}
ll inv(ll n, ll p){ return power(n,p-2, p); }
bool isPrime(ll n) {
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (ll i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
            return false;
    return true;
}

const int maxn=1000001;
int n;
int h = sizeof(int) * 8 - __builtin_clz(n);
int t[2*maxn][4];
bool lazy[maxn];

void apply(int p)
{
    swap(t[p][0],t[p][1]);
    swap(t[p][2],t[p][3]);
    if(p<n) lazy[p] = !lazy[p];
}

void build(int i)
{
    while(i>1)
    {
        i>>=1;
        int c1=i*2;
        int c2=c1+1;
        t[i][0]=t[c1][0]+t[c2][0];
        t[i][1]=t[c1][1]+t[c2][1];
        t[i][2]=max({t[c1][2]+t[c2][1],t[c1][0]+t[c2][2],t[c1][0]+t[c2][1]});
        t[i][3]=max({t[c1][3]+t[c2][0],t[c1][1]+t[c2][3],t[c1][1]+t[c2][0]});
        if(lazy[i])
        {
            swap(t[i][0],t[i][1]);
            swap(t[i][2],t[i][3]);
        }
    }
}

void push(int p)
{
    for(int s=h;s>0;s--)
    {
        int i = p>>s;
        if (lazy[i])
        {
            apply(i<<1);
            apply(i<<1|1);
            lazy[i] = false;
        }
    }
}

void swtch(int l,int r)
{
    l+=n-1,r+=n;
    int l0=l,r0=r;
    while(l<r)
    {
        if(l&1) apply(l++);
        if(r&1) apply(--r);
        l>>=1,r>>=1;
    }
    build(l0);
    build(r0-1);
}

int query(int l, int r)
{
    l+=n-1,r+=n;
    push(l);
    push(r-1);
    int a[4],b[4];
    MS0(a);
    MS0(b);
    while(l<r)
    {
        if(l&1)
        {
            a[2] = max({a[0]+t[l][1],a[2]+t[l][1],a[0]+t[l][2]});
            a[3] = max({a[1]+t[l][0],a[3]+t[l][0],a[1]+t[l][3]});
            a[0] += t[l][0];
            a[1] += t[l][1];
            l+=1;
        }
        if(r&1)
        {
            r-=1;
            b[2] = max({b[1]+t[r][0],b[1]+t[r][2],b[2]+t[r][0]});
            b[3] = max({b[0]+t[r][1],b[0]+t[r][3],b[3]+t[r][1]});
            b[0] += t[r][0];
            b[1] += t[r][1];
        }
        l>>=1,r>>=1;
    }
    // cout<<l<<' '<<r<<'\n';
    // cout<<a[2]+b[1]<<' '<<a[0]+b[2]<<' '<<a[0]+b[1]<<'\n';
    return (1) ? max({a[2]+b[1],a[0]+b[2],a[0]+b[1]}) : a[2];
    // return a[2];
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int m;
    cin>>n>>m;
    char dig;
    rep(i,n)
    {
        cin>>dig;
        // cout<<dig<<endl;
        int x;
        (dig=='4') ? x=0:x=1;
        t[i+n][0]=x^1;
        t[i+n][1]=x^0;
        t[i+n][2]=t[i+n][3]=1;
    }
    pera(i,n-1,1)
    {
        int c1=i<<1;
        int c2=c1+1;
        t[i][0]=t[c1][0]+t[c2][0];
        t[i][1]=t[c1][1]+t[c2][1];
        t[i][2]=max({t[c1][2]+t[c2][1],t[c1][0]+t[c2][2],t[c1][0]+t[c2][1]});
        t[i][3]=max({t[c1][3]+t[c2][0],t[c1][1]+t[c2][3],t[c1][1]+t[c2][0]});
    }
    MS0(lazy);
    while(m--)
    {
        string s;
        cin>>s;
        // cout<<s<<endl;
        if(s=="count") cout<<query(1,n)<<endl;
        else
        {
            int l,r;
            cin>>l>>r;
            swtch(l,r);
        }
    }
    // repa(i,1,2*n) cout<<t[i][0]<<' ';

    return 0;
}


/**         (buri nazar wale tera muh kala 😑)
 *
 * @Author   : rudraksh
 * @Created  : Wednesday, May 27th 2020, 10:11:16 pm
 * @Email    : rudrakshk@iitbhilai.ac.in
 *
 *   Always give 100% — unless you’re donating blood.
 */

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

typedef long long int ll;
typedef unsigned long long ull;
typedef double db;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef map<int,int> MI;
typedef vector<VI> VVI;
typedef pair<int,PI> PIP;

#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define mp make_pair
#define repa(i,a,n) for(ll i=a;i<n;i++)
#define rep(i,n) for(ll i=0;i<n;i++)
#define pera(i,a,n) for(ll i=a;i>=n;i--)
#define per(i,n) for(ll i=n;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define loop(it,x) for(auto it=x.begin();it!=x.end();it++)
#define MS0(x) memset((x), 0, sizeof((x)))
#define MS1(x) memset((x), -1, sizeof((x)))
#define CP(dst,src) memcpy(dst, src, sizeof(src));
#define SZ(x) ((ll)(x).size())
#define TIME    cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";

const ll mod=1e9+7;
const double pi=acos(-1);

ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
ll power(ll a,ll b,ll p) //log(b)
{
    if(b==0) return 1;
    ll c = power(a,b/2,p);
    if(b%2==0) return (c*c)%p;
    else return (((c*c)%p)*a)%p;
}
ll inv(ll n, ll p){ return power(n,p-2, p); }
bool isPrime(ll n) {
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (ll i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
            return false;
    return true;
}

const int maxn=1000001;
int n;
int h;
int t[2*maxn][4];
bool lazy[2*maxn];

void apply(int p, bool val)
{
    swap(t[p][0],t[p][1]);
    swap(t[p][2],t[p][3]);
    if(p<n) lazy[p] |= val;
}

void build(int i)
{
    while(i>1)
    {
        i>>=1;
        int c1=i*2;
        int c2=c1+1;
        t[i][0]=t[c1][0]+t[c2][0];
        t[i][1]=t[c1][1]+t[c2][1];
        t[i][2]=max({t[c1][2]+t[c2][1],t[c1][0]+t[c2][2],t[c1][0]+t[c2][1]});
        t[i][3]=max({t[c1][3]+t[c2][0],t[c1][1]+t[c2][3],t[c1][1]+t[c2][0]});
        if(lazy[i])
        {
            swap(t[i][0],t[i][1]);
            swap(t[i][2],t[i][3]);
        }
    }
}

void push(int p)
{
    for(int s=h;s>0;s--)
    {
        int i = p>>s;
        if (lazy[i])
        {
            apply(i<<1, lazy[i]);
            apply(i<<1|1, lazy[i]);
            lazy[i] = false;
        }
    }
}

void swtch(int l,int r)
{
    l+=n-1,r+=n;
    int l0=l,r0=r;
    while(l<r)
    {
        if(l&1) apply(l++,true);
        if(r&1) apply(--r,true);
        l>>=1,r>>=1;
    }
    build(l0);
    build(r0-1);
}

int query(int l, int r)
{
    l+=n-1,r+=n;
    push(l);
    push(r-1);
    int a[4],b[4];
    MS0(a);
    MS0(b);
    while(l<r)
    {
        if(l&1)
        {
            a[2] = max({a[0]+t[l][1],a[2]+t[l][1],a[0]+t[l][2]});
            a[3] = max({a[1]+t[l][0],a[3]+t[l][0],a[1]+t[l][3]});
            a[0] += t[l][0];
            a[1] += t[l][1];
            l+=1;
        }
        if(r&1)
        {
            r-=1;
            b[2] = max({b[1]+t[r][0],b[1]+t[r][2],b[2]+t[r][0]});
            b[3] = max({b[0]+t[r][1],b[0]+t[r][3],b[3]+t[r][1]});
            b[0] += t[r][0];
            b[1] += t[r][1];
        }
        l>>=1,r>>=1;
    }
    // cout<<l<<' '<<r<<'\n';
    // cout<<a[2]+b[1]<<' '<<a[0]+b[2]<<' '<<a[0]+b[1]<<'\n';
    return (1) ? max({a[2]+b[1],a[0]+b[2],a[0]+b[1]}) : a[2];
    // return a[2];
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int m;
    cin>>n>>m;
    h=sizeof(int) * 8 - __builtin_clz(n);
    char dig;
    rep(i,n)
    {
        cin>>dig;
        // cout<<dig<<endl;
        int x;
        (dig=='4') ? x=0:x=1;
        t[i+n][0]=x^1;
        t[i+n][1]=x^0;
        t[i+n][2]=t[i+n][3]=1;
    }
    pera(i,n-1,1)
    {
        int c1=i<<1;
        int c2=c1+1;
        t[i][0]=t[c1][0]+t[c2][0];
        t[i][1]=t[c1][1]+t[c2][1];
        t[i][2]=max({t[c1][2]+t[c2][1],t[c1][0]+t[c2][2],t[c1][0]+t[c2][1]});
        t[i][3]=max({t[c1][3]+t[c2][0],t[c1][1]+t[c2][3],t[c1][1]+t[c2][0]});
    }
    MS0(lazy);
    while(m--)
    {
        string s;
        cin>>s;
        // cout<<s<<endl;
        if(s=="count") cout<<query(1,n)<<'\n';
        else
        {
            int l,r;
            cin>>l>>r;
            swtch(l,r);
        }
    }
    // repa(i,1,2*n) cout<<t[i][0]<<' ';

    return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define REP(i,a,b) for(ll i=a; i<b; i++)
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define ff first
#define ss second
#define INF 100000000000000000LL
ll insig;
#define In(vecBRO, LENBRO) REP(IBRO,0,LENBRO) {cin>>insig; vecBRO.pb(insig);}
void Out(vector<ll> x) {REP(i,0,x.size()) {cout<<x[i]<<" ";} cout<<endl;}

class ST
{
    public:
    ll N; vector<pl> ar; vector<pl> p;
    pl neut; pl neutla;
    vector<pl> lazy;

    pl op(pl a, pl b) //how seg values interact
    {
        return mp(min(a.ff,b.ff),max(a.ss,b.ss));
    }

    pl upval(ll c, ll x, ll y) //how lazy values modify a node
    {
        pl la=lazy[c];
        pl sv=p[c];
        if(la.ff>=0)
        {
            return mp(la.ff*sv.ff+la.ss,la.ff*sv.ss+la.ss);
        }
        else
        {
            return mp(la.ff*sv.ss+la.ss,la.ff*sv.ff+la.ss);
        }
    }

    pl inter(pl lv1,pl lv2) //how lazy values interact
    {
        return mp(lv1.ff*lv2.ff,lv1.ff*lv2.ss+lv1.ss);
    }

    ST(vector<ll> arr)
    {
        neut=mp(INF,-INF); neutla=mp(1,0);
        N = (ll) 1<<(ll) ceil(log2(arr.size()));
        REP(i,0,arr.size()) {ar.pb(mp(arr[i],arr[i]));}
        REP(i,arr.size(),N) {ar.pb(neut);}
        REP(i,0,N) {p.pb(neut);}
        REP(i,0,N) {p.pb(ar[i]);}
        ll cur = N-1;
        while(cur>0)
        {
            p[cur]=op(p[2*cur],p[2*cur+1]);
            cur--;
        }
        REP(i,0,2*N) {lazy.pb(neutla);}
    }

    void prop(ll c, ll x, ll y) //how lazy values propagate
    {
        p[c]=upval(c,x,y);
        lazy[2*c]=inter(lazy[c],lazy[2*c]); lazy[2*c+1]=inter(lazy[c],lazy[2*c+1]);
        lazy[c]=neutla;
        if(2*c>=N)
        {
            p[2*c]=upval(2*c,2*c,2*c); p[2*c+1]=upval(2*c+1,2*c+1,2*c+1);
            ar[2*c-N]=p[2*c];
            ar[2*c+1-N]=p[2*c+1];
            lazy[2*c]=neutla; lazy[2*c+1]=neutla;
        }
    }

    pl query(ll a,ll b, ll c, ll x, ll y) //c=current node, starting in 1, a,b=range of query, x,y=range of node c in the array down, x,y from 0 to N-1. query(a,b)->query(a,b,1,0,N-1)
    {
        if(y<a || x>b) {return neut;}
        if(x>=a && y<=b) {return upval(c,x,y);}
        prop(c,x,y);
        ll mid=(x+y)/2;
        pl ans = op(query(a,b,2*c,x,mid),query(a,b,2*c+1,mid+1,y));
        return ans;
    }

    void update(pl s, ll a, ll b, ll c, ll x, ll y) //positions in [a,b] from 0 to N-1 gets +s
    {
        if(y<a || x>b) {return ;}
        if(x>=a && y<=b)
        {
            lazy[c]=inter(s,lazy[c]);
            if(c>=N) {p[c]=upval(c,c,c); lazy[c]=neutla; ar[c-N]=p[c];}
            return;
        }
        ll mid=(x+y)/2;
        update(s,a,b,2*c,x,mid); update(s,a,b,2*c+1,mid+1,y);
        p[c]=op(upval(2*c,x,mid),upval(2*c+1,mid+1,y));
    }
};

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll N,Q; cin>>N>>Q;
    string s; cin>>s;
    vector<ll> arr,ps; ll sum=0;
    REP(i,0,N)
    {
        if(s[i]=='4') {arr.pb(-1); sum-=1;ps.pb(sum);}
        else {arr.pb(1); sum+=1;ps.pb(sum);}
    }
    ST S(ps);
    string com; ll a,b;
    ll n1;
    REP(q,0,Q)
    {
        cin>>com;
        if(com=="switch")
        {
            cin>>a>>b; a--; b--;
            pl t1,t2;
            if(a>0)
            {
                t1=mp(-1,2*S.query(a-1,a-1,1,0,S.N-1).ff);
                t2=mp(1,-2*(S.query(b,b,1,0,S.N-1).ff-S.query(a-1,a-1,1,0,S.N-1).ff));
            }
            else
            {
                t1=mp(-1,0);
                t2=mp(1,-2*S.query(b,b,1,0,S.N-1).ff);
            }
            S.update(t1,a,b,1,0,S.N-1);
            if(b<N-1) {S.update(t2,b+1,N-1,1,0,S.N-1);}
        }
        else
        {
            ll val=max(0LL,-S.query(0,S.N-1,1,0,S.N-1).ff);
            n1=(S.query(N-1,N-1,1,0,S.N-1).ff+N)/2;
            cout<<val+n1<<"\n";
        }

    }
    return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define REP(i,a,b) for(ll i=a; i<b; i++)
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define ff first
#define ss second
#define INF 100000000000000000LL
ll insig;
#define In(vecBRO, LENBRO) REP(IBRO,0,LENBRO) {cin>>insig; vecBRO.pb(insig);}
void Out(vector<ll> x) {REP(i,0,x.size()) {cout<<x[i]<<" ";} cout<<endl;}

class ST
{
    public:
    ll N; vector<pl> ar; vector<pl> p;
    pl neut; pl neutla;
    vector<pl> lazy;

    pl op(pl a, pl b) //how seg values interact
    {
        return mp(min(a.ff,b.ff),max(a.ss,b.ss));
    }

    pl upval(ll c, ll x, ll y) //how lazy values modify a node
    {
        pl la=lazy[c];
        pl sv=p[c];
        if(la.ff>=0)
        {
            return mp(la.ff*sv.ff+la.ss,la.ff*sv.ss+la.ss);
        }
        else
        {
            return mp(la.ff*sv.ss+la.ss,la.ff*sv.ff+la.ss);
        }
    }

    pl inter(pl lv1,pl lv2) //how lazy values interact
    {
        return mp(lv1.ff*lv2.ff,lv1.ff*lv2.ss+lv1.ss);
    }

    ST(vector<ll> arr)
    {
        neut=mp(INF,-INF); neutla=mp(1,0);
        N = (ll) 1<<(ll) ceil(log2(arr.size()));
        REP(i,0,arr.size()) {ar.pb(mp(arr[i],arr[i]));}
        REP(i,arr.size(),N) {ar.pb(neut);}
        REP(i,0,N) {p.pb(neut);}
        REP(i,0,N) {p.pb(ar[i]);}
        ll cur = N-1;
        while(cur>0)
        {
            p[cur]=op(p[2*cur],p[2*cur+1]);
            cur--;
        }
        REP(i,0,2*N) {lazy.pb(neutla);}
    }

    void prop(ll c, ll x, ll y) //how lazy values propagate
    {
        p[c]=upval(c,x,y);
        lazy[2*c]=inter(lazy[c],lazy[2*c]); lazy[2*c+1]=inter(lazy[c],lazy[2*c+1]);
        lazy[c]=neutla;
        if(2*c>=N)
        {
            p[2*c]=upval(2*c,2*c,2*c); p[2*c+1]=upval(2*c+1,2*c+1,2*c+1);
            ar[2*c-N]=p[2*c];
            ar[2*c+1-N]=p[2*c+1];
            lazy[2*c]=neutla; lazy[2*c+1]=neutla;
        }
    }

    pl query(ll a,ll b, ll c, ll x, ll y) //c=current node, starting in 1, a,b=range of query, x,y=range of node c in the array down, x,y from 0 to N-1. query(a,b)->query(a,b,1,0,N-1)
    {
        if(y<a || x>b) {return neut;}
        if(x>=a && y<=b) {return upval(c,x,y);}
        prop(c,x,y);
        ll mid=(x+y)/2;
        pl ans = op(query(a,b,2*c,x,mid),query(a,b,2*c+1,mid+1,y));
        return ans;
    }

    void update(pl s, ll a, ll b, ll c, ll x, ll y) //positions in [a,b] from 0 to N-1 gets +s
    {
        if(y<a || x>b) {return ;}
        if(x>=a && y<=b)
        {
            lazy[c]=inter(s,lazy[c]);
            if(c>=N) {p[c]=upval(c,c,c); lazy[c]=neutla; ar[c-N]=p[c];}
            return;
        }
        ll mid=(x+y)/2;
        update(s,a,b,2*c,x,mid); update(s,a,b,2*c+1,mid+1,y);
        p[c]=op(upval(2*c,x,mid),upval(2*c+1,mid+1,y));
    }
};

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll N,Q; cin>>N>>Q;
    string s; cin>>s;
    vector<ll> arr,ps; ll sum=0;
    REP(i,0,N)
    {
        if(s[i]=='4') {arr.pb(-1); sum-=1;ps.pb(sum);}
        else {arr.pb(1); sum+=1;ps.pb(sum);}
    }
    ST S(ps);
    string com; ll a,b;
    REP(q,0,Q)
    {
        cin>>com;
        if(com=="switch")
        {
            cin>>a>>b; a--; b--;
            pl t1,t2;
            if(a>0)
            {
                t1=mp(-1,2*S.ar[a-1].ff);
                t2=mp(1,-2*(S.ar[b].ff-S.ar[a-1].ff));
            }
            else
            {
                t1=mp(-1,0);
                t2=mp(1,-2*S.ar[b].ff);
            }
            S.update(t1,a,b,1,0,S.N-1);
            if(b<N-1) {S.update(t2,b+1,N-1,1,0,S.N-1);}
        }
        else
        {
            ll val=max(0LL,-S.query(0,S.N-1,1,0,S.N-1).ff);
            ll n1=(S.query(N-1,N-1,1,0,S.N-1).ff+N)/2;
            cout<<val+n1<<endl;
        }
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define REP(i,a,b) for(ll i=a; i<b; i++)
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define ff first
#define ss second
#define INF 100000000000
ll insig;
#define In(vecBRO, LENBRO) REP(IBRO,0,LENBRO) {cin>>insig; vecBRO.pb(insig);}
void Out(vector<ll> x) {REP(i,0,x.size()) {cout<<x[i]<<" ";} cout<<endl;}

class ST
{
    public:
    ll N; vector<pl> ar; vector<pl> p;
    pl neut; pl neutla;
    vector<pl> lazy;

    pl op(pl a, pl b) //how seg values interact
    {
        return mp(min(a.ff,b.ff),max(a.ss,b.ss));
    }

    pl upval(ll c, ll x, ll y) //how lazy values modify a node
    {
        pl la=lazy[c];
        pl sv=p[c];
        if(la.ff>=0)
        {
            return mp(la.ff*sv.ff+la.ss,la.ff*sv.ss+la.ss);
        }
        else
        {
            return mp(la.ff*sv.ss+la.ss,la.ff*sv.ff+la.ss);
        }
    }

    pl inter(pl lv1,pl lv2) //how lazy values interact
    {
        return mp(lv1.ff*lv2.ff,lv1.ff*lv2.ss+lv1.ss);
    }

    ST(vector<ll> arr)
    {
        neut=mp(INF,-INF); neutla=mp(1,0);
        N = (ll) 1<<(ll) ceil(log2(arr.size()));
        REP(i,0,arr.size()) {ar.pb(mp(arr[i],arr[i]));}
        REP(i,arr.size(),N) {ar.pb(neut);}
        REP(i,0,N) {p.pb(neut);}
        REP(i,0,N) {p.pb(ar[i]);}
        ll cur = N-1;
        while(cur>0)
        {
            p[cur]=op(p[2*cur],p[2*cur+1]);
            cur--;
        }
        REP(i,0,2*N) {lazy.pb(neutla);}
    }

    void prop(ll c, ll x, ll y) //how lazy values propagate
    {
        p[c]=upval(c,x,y);
        lazy[2*c]=inter(lazy[c],lazy[2*c]); lazy[2*c+1]=inter(lazy[c],lazy[2*c+1]);
        lazy[c]=neutla;
        if(2*c>=N)
        {
            p[2*c]=upval(2*c,2*c,2*c); p[2*c+1]=upval(2*c+1,2*c+1,2*c+1);
            ar[2*c-N]=p[2*c];
            ar[2*c+1-N]=p[2*c+1];
            lazy[2*c]=neutla; lazy[2*c+1]=neutla;
        }
    }

    pl query(ll a,ll b, ll c, ll x, ll y) //c=current node, starting in 1, a,b=range of query, x,y=range of node c in the array down, x,y from 0 to N-1. query(a,b)->query(a,b,1,0,N-1)
    {
        if(y<a || x>b) {return neut;}
        if(x>=a && y<=b) {return upval(c,x,y);}
        prop(c,x,y);
        ll mid=(x+y)/2;
        pl ans = op(query(a,b,2*c,x,mid),query(a,b,2*c+1,mid+1,y));
        return ans;
    }

    void update(pl s, ll a, ll b, ll c, ll x, ll y) //positions in [a,b] from 0 to N-1 gets +s
    {
        if(y<a || x>b) {return ;}
        if(x>=a && y<=b)
        {
            lazy[c]=inter(s,lazy[c]);
            if(c>=N) {p[c]=upval(c,c,c); lazy[c]=neutla; ar[c-N]=p[c];}
            return;
        }
        ll mid=(x+y)/2;
        update(s,a,b,2*c,x,mid); update(s,a,b,2*c+1,mid+1,y);
        p[c]=op(upval(2*c,x,mid),upval(2*c+1,mid+1,y));
    }
};

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll N,Q; cin>>N>>Q;
    string s; cin>>s;
    vector<ll> arr,ps; ll sum=0;
    REP(i,0,N)
    {
        if(s[i]=='4') {arr.pb(-1); sum-=1;ps.pb(sum);}
        else {arr.pb(1); sum+=1;ps.pb(sum);}
    }
    ST S(ps);
    string com; ll a,b;
    ll n1;
    REP(q,0,Q)
    {
        cin>>com;
        if(com=="switch")
        {
            cin>>a>>b; a--; b--;
            pl t1,t2;
            if(a>0)
            {
                t1=mp(-1,2*S.query(a-1,a-1,1,0,S.N-1).ff);
                t2=mp(1,-2*(S.query(b,b,1,0,S.N-1).ff-S.query(a-1,a-1,1,0,S.N-1).ff));
            }
            else
            {
                t1=mp(-1,0);
                t2=mp(1,-2*S.query(b,b,1,0,S.N-1).ff);
            }
            S.update(t1,a,b,1,0,S.N-1);
            if(b<N-1) {S.update(t2,b+1,N-1,1,0,S.N-1);}
        }
        else
        {
            ll val=max(0,-S.query(0,S.N-1,1,0,S.N-1).ff);
            n1=(S.query(N-1,N-1,1,0,S.N-1).ff+N)/2;
            cout<<val+n1<<"\n";
        }

    }
    return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define REP(i,a,b) for(ll i=a; i<b; i++)
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define ff first
#define ss second
#define INF 100000000000000000LL
ll insig;
#define In(vecBRO, LENBRO) REP(IBRO,0,LENBRO) {cin>>insig; vecBRO.pb(insig);}
void Out(vector<ll> x) {REP(i,0,x.size()) {cout<<x[i]<<" ";} cout<<endl;}

class ST
{
    public:
    ll N; vector<pl> ar; vector<pl> p;
    pl neut; pl neutla;
    vector<pl> lazy;

    pl op(pl a, pl b) //how seg values interact
    {
        return mp(min(a.ff,b.ff),max(a.ss,b.ss));
    }

    pl upval(ll c, ll x, ll y) //how lazy values modify a node
    {
        pl la=lazy[c];
        pl sv=p[c];
        if(la.ff>=0)
        {
            return mp(la.ff*sv.ff+la.ss,la.ff*sv.ss+la.ss);
        }
        else
        {
            return mp(la.ff*sv.ss+la.ss,la.ff*sv.ff+la.ss);
        }
    }

    pl inter(pl lv1,pl lv2) //how lazy values interact
    {
        return mp(lv1.ff*lv2.ff,lv1.ff*lv2.ss+lv1.ss);
    }

    ST(vector<ll> arr)
    {
        neut=mp(INF,-INF); neutla=mp(1,0);
        N = (ll) 1<<(ll) ceil(log2(arr.size()));
        REP(i,0,arr.size()) {ar.pb(mp(arr[i],arr[i]));}
        REP(i,arr.size(),N) {ar.pb(neut);}
        REP(i,0,N) {p.pb(neut);}
        REP(i,0,N) {p.pb(ar[i]);}
        ll cur = N-1;
        while(cur>0)
        {
            p[cur]=op(p[2*cur],p[2*cur+1]);
            cur--;
        }
        REP(i,0,2*N) {lazy.pb(neutla);}
    }

    void prop(ll c, ll x, ll y) //how lazy values propagate
    {
        p[c]=upval(c,x,y);
        lazy[2*c]=inter(lazy[c],lazy[2*c]); lazy[2*c+1]=inter(lazy[c],lazy[2*c+1]);
        lazy[c]=neutla;
        if(2*c>=N)
        {
            p[2*c]=upval(2*c,2*c,2*c); p[2*c+1]=upval(2*c+1,2*c+1,2*c+1);
            ar[2*c-N]=p[2*c];
            ar[2*c+1-N]=p[2*c+1];
            lazy[2*c]=neutla; lazy[2*c+1]=neutla;
        }
    }

    pl query(ll a,ll b, ll c, ll x, ll y) //c=current node, starting in 1, a,b=range of query, x,y=range of node c in the array down, x,y from 0 to N-1. query(a,b)->query(a,b,1,0,N-1)
    {
        if(y<a || x>b) {return neut;}
        if(x>=a && y<=b) {return upval(c,x,y);}
        prop(c,x,y);
        ll mid=(x+y)/2;
        pl ans = op(query(a,b,2*c,x,mid),query(a,b,2*c+1,mid+1,y));
        return ans;
    }

    void update(pl s, ll a, ll b, ll c, ll x, ll y) //positions in [a,b] from 0 to N-1 gets +s
    {
        if(y<a || x>b) {return ;}
        if(x>=a && y<=b)
        {
            lazy[c]=inter(s,lazy[c]);
            if(c>=N) {p[c]=upval(c,c,c); lazy[c]=neutla; ar[c-N]=p[c];}
            return;
        }
        ll mid=(x+y)/2;
        update(s,a,b,2*c,x,mid); update(s,a,b,2*c+1,mid+1,y);
        p[c]=op(upval(2*c,x,mid),upval(2*c+1,mid+1,y));
    }
};

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll N,Q; cin>>N>>Q;
    string s; cin>>s;
    vector<ll> arr,ps; ll sum=0;
    REP(i,0,N)
    {
        if(s[i]=='4') {arr.pb(-1); sum-=1;ps.pb(sum);}
        else {arr.pb(1); sum+=1;ps.pb(sum);}
    }
    ST S(ps);
    string com; ll a,b;
    ll n1;
    REP(q,0,Q)
    {
        cin>>com;
        if(com=="switch")
        {
            cin>>a>>b; a--; b--;
            pl t1,t2;
            if(a>0)
            {
                t1=mp(-1,2*S.query(a-1,a-1,1,0,S.N-1).ff);
                t2=mp(1,-2*(S.query(b,b,1,0,S.N-1).ff-S.query(a-1,a-1,1,0,S.N-1).ff));
            }
            else
            {
                t1=mp(-1,0);
                t2=mp(1,-2*S.query(b,b,1,0,S.N-1).ff);
            }
            S.update(t1,a,b,1,0,S.N-1);
            if(b<N-1) {S.update(t2,b+1,N-1,1,0,S.N-1);}
        }
        else
        {
            ll val=max(0LL,-S.query(0,S.N-1,1,0,S.N-1).ff);
            n1=(S.query(N-1,N-1,1,0,S.N-1).ff+N)/2;
            cout<<val+n1<<endl;
        }

    }
    return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <set>
using namespace std;
typedef int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define REP(i,a,b) for(ll i=a; i<b; i++)
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define ff first
#define ss second
#define INF 1000000000LL
ll insig;
#define In(vecBRO, LENBRO) REP(IBRO,0,LENBRO) {cin>>insig; vecBRO.pb(insig);}
void Out(vector<ll> x) {REP(i,0,x.size()) {cout<<x[i]<<" ";} cout<<endl;}

class ST
{
    public:
    ll N; vector<pl> ar; vector<pl> p;
    pl neut; pl neutla;
    vector<pl> lazy;

    pl op(pl a, pl b) //how seg values interact
    {
        return mp(min(a.ff,b.ff),max(a.ss,b.ss));
    }

    pl upval(ll c, ll x, ll y) //how lazy values modify a node
    {
        pl la=lazy[c];
        pl sv=p[c];
        if(la.ff>=0)
        {
            return mp(la.ff*sv.ff+la.ss,la.ff*sv.ss+la.ss);
        }
        else
        {
            return mp(la.ff*sv.ss+la.ss,la.ff*sv.ff+la.ss);
        }
    }

    pl inter(pl lv1,pl lv2) //how lazy values interact
    {
        return mp(lv1.ff*lv2.ff,lv1.ff*lv2.ss+lv1.ss);
    }

    ST(vector<ll> arr)
    {
        neut=mp(INF,-INF); neutla=mp(1,0);
        N = (ll) 1<<(ll) ceil(log2(arr.size()));
        REP(i,0,arr.size()) {ar.pb(mp(arr[i],arr[i]));}
        REP(i,arr.size(),N) {ar.pb(neut);}
        REP(i,0,N) {p.pb(neut);}
        REP(i,0,N) {p.pb(ar[i]);}
        ll cur = N-1;
        while(cur>0)
        {
            p[cur]=op(p[2*cur],p[2*cur+1]);
            cur--;
        }
        REP(i,0,2*N) {lazy.pb(neutla);}
    }

    void prop(ll c, ll x, ll y) //how lazy values propagate
    {
        p[c]=upval(c,x,y);
        lazy[2*c]=inter(lazy[c],lazy[2*c]); lazy[2*c+1]=inter(lazy[c],lazy[2*c+1]);
        lazy[c]=neutla;
        if(2*c>=N)
        {
            p[2*c]=upval(2*c,2*c,2*c); p[2*c+1]=upval(2*c+1,2*c+1,2*c+1);
            ar[2*c-N]=p[2*c];
            ar[2*c+1-N]=p[2*c+1];
            lazy[2*c]=neutla; lazy[2*c+1]=neutla;
        }
    }

    pl query(ll a,ll b, ll c, ll x, ll y) //c=current node, starting in 1, a,b=range of query, x,y=range of node c in the array down, x,y from 0 to N-1. query(a,b)->query(a,b,1,0,N-1)
    {
        if(y<a || x>b) {return neut;}
        if(x>=a && y<=b) {return upval(c,x,y);}
        prop(c,x,y);
        ll mid=(x+y)/2;
        pl ans = op(query(a,b,2*c,x,mid),query(a,b,2*c+1,mid+1,y));
        return ans;
    }

    void update(pl s, ll a, ll b, ll c, ll x, ll y) //positions in [a,b] from 0 to N-1 gets +s
    {
        if(y<a || x>b) {return ;}
        if(x>=a && y<=b)
        {
            lazy[c]=inter(s,lazy[c]);
            if(c>=N) {p[c]=upval(c,c,c); lazy[c]=neutla; ar[c-N]=p[c];}
            return;
        }
        ll mid=(x+y)/2;
        update(s,a,b,2*c,x,mid); update(s,a,b,2*c+1,mid+1,y);
        p[c]=op(upval(2*c,x,mid),upval(2*c+1,mid+1,y));
    }
};

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll N,Q; cin>>N>>Q;
    string s; cin>>s;
    vector<ll> arr,ps; ll sum=0;
    REP(i,0,N)
    {
        if(s[i]=='4') {arr.pb(-1); sum-=1;ps.pb(sum);}
        else {arr.pb(1); sum+=1;ps.pb(sum);}
    }
    ST S(ps);
    string com; ll a,b;
    ll n1;
    REP(q,0,Q)
    {
        cin>>com;
        if(com=="switch")
        {
            cin>>a>>b; a--; b--;
            pl t1,t2;
            if(a>0)
            {
                t1=mp(-1,2*S.query(a-1,a-1,1,0,S.N-1).ff);
                t2=mp(1,-2*(S.query(b,b,1,0,S.N-1).ff-S.query(a-1,a-1,1,0,S.N-1).ff));
            }
            else
            {
                t1=mp(-1,0);
                t2=mp(1,-2*S.query(b,b,1,0,S.N-1).ff);
            }
            S.update(t1,a,b,1,0,S.N-1);
            if(b<N-1) {S.update(t2,b+1,N-1,1,0,S.N-1);}
        }
        else
        {
            ll val=max(0,-S.query(0,S.N-1,1,0,S.N-1).ff);
            n1=(S.query(N-1,N-1,1,0,S.N-1).ff+N)/2;
            cout<<val+n1<<"\n";
        }

    }
    return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <set>
using namespace std;
typedef int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define REP(i,a,b) for(ll i=a; i<b; i++)
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define ff first
#define ss second
#define INF 100000000000
ll insig;
#define In(vecBRO, LENBRO) REP(IBRO,0,LENBRO) {cin>>insig; vecBRO.pb(insig);}
void Out(vector<ll> x) {REP(i,0,x.size()) {cout<<x[i]<<" ";} cout<<endl;}

class ST
{
    public:
    ll N; vector<pl> ar; vector<pl> p;
    pl neut; pl neutla;
    vector<pl> lazy;

    pl op(pl a, pl b) //how seg values interact
    {
        return mp(min(a.ff,b.ff),max(a.ss,b.ss));
    }

    pl upval(ll c, ll x, ll y) //how lazy values modify a node
    {
        pl la=lazy[c];
        pl sv=p[c];
        if(la.ff>=0)
        {
            return mp(la.ff*sv.ff+la.ss,la.ff*sv.ss+la.ss);
        }
        else
        {
            return mp(la.ff*sv.ss+la.ss,la.ff*sv.ff+la.ss);
        }
    }

    pl inter(pl lv1,pl lv2) //how lazy values interact
    {
        return mp(lv1.ff*lv2.ff,lv1.ff*lv2.ss+lv1.ss);
    }

    ST(vector<ll> arr)
    {
        neut=mp(INF,-INF); neutla=mp(1,0);
        N = (ll) 1<<(ll) ceil(log2(arr.size()));
        REP(i,0,arr.size()) {ar.pb(mp(arr[i],arr[i]));}
        REP(i,arr.size(),N) {ar.pb(neut);}
        REP(i,0,N) {p.pb(neut);}
        REP(i,0,N) {p.pb(ar[i]);}
        ll cur = N-1;
        while(cur>0)
        {
            p[cur]=op(p[2*cur],p[2*cur+1]);
            cur--;
        }
        REP(i,0,2*N) {lazy.pb(neutla);}
    }

    void prop(ll c, ll x, ll y) //how lazy values propagate
    {
        p[c]=upval(c,x,y);
        lazy[2*c]=inter(lazy[c],lazy[2*c]); lazy[2*c+1]=inter(lazy[c],lazy[2*c+1]);
        lazy[c]=neutla;
        if(2*c>=N)
        {
            p[2*c]=upval(2*c,2*c,2*c); p[2*c+1]=upval(2*c+1,2*c+1,2*c+1);
            ar[2*c-N]=p[2*c];
            ar[2*c+1-N]=p[2*c+1];
            lazy[2*c]=neutla; lazy[2*c+1]=neutla;
        }
    }

    pl query(ll a,ll b, ll c, ll x, ll y) //c=current node, starting in 1, a,b=range of query, x,y=range of node c in the array down, x,y from 0 to N-1. query(a,b)->query(a,b,1,0,N-1)
    {
        if(y<a || x>b) {return neut;}
        if(x>=a && y<=b) {return upval(c,x,y);}
        prop(c,x,y);
        ll mid=(x+y)/2;
        pl ans = op(query(a,b,2*c,x,mid),query(a,b,2*c+1,mid+1,y));
        return ans;
    }

    void update(pl s, ll a, ll b, ll c, ll x, ll y) //positions in [a,b] from 0 to N-1 gets +s
    {
        if(y<a || x>b) {return ;}
        if(x>=a && y<=b)
        {
            lazy[c]=inter(s,lazy[c]);
            if(c>=N) {p[c]=upval(c,c,c); lazy[c]=neutla; ar[c-N]=p[c];}
            return;
        }
        ll mid=(x+y)/2;
        update(s,a,b,2*c,x,mid); update(s,a,b,2*c+1,mid+1,y);
        p[c]=op(upval(2*c,x,mid),upval(2*c+1,mid+1,y));
    }
};

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll N,Q; cin>>N>>Q;
    string s; cin>>s;
    vector<ll> arr,ps; ll sum=0;
    REP(i,0,N)
    {
        if(s[i]=='4') {arr.pb(-1); sum-=1;ps.pb(sum);}
        else {arr.pb(1); sum+=1;ps.pb(sum);}
    }
    ST S(ps);
    string com; ll a,b;
    ll n1;
    REP(q,0,Q)
    {
        cin>>com;
        if(com=="switch")
        {
            cin>>a>>b; a--; b--;
            pl t1,t2;
            if(a>0)
            {
                t1=mp(-1,2*S.query(a-1,a-1,1,0,S.N-1).ff);
                t2=mp(1,-2*(S.query(b,b,1,0,S.N-1).ff-S.query(a-1,a-1,1,0,S.N-1).ff));
            }
            else
            {
                t1=mp(-1,0);
                t2=mp(1,-2*S.query(b,b,1,0,S.N-1).ff);
            }
            S.update(t1,a,b,1,0,S.N-1);
            if(b<N-1) {S.update(t2,b+1,N-1,1,0,S.N-1);}
        }
        else
        {
            ll val=max(0,-S.query(0,S.N-1,1,0,S.N-1).ff);
            n1=(S.query(N-1,N-1,1,0,S.N-1).ff+N)/2;
            cout<<val+n1<<"\n";
        }

    }
    return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define REP(i,a,b) for(ll i=a; i<b; i++)
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define ff first
#define ss second
#define INF 100000000000000000LL
ll insig;
#define In(vecBRO, LENBRO) REP(IBRO,0,LENBRO) {cin>>insig; vecBRO.pb(insig);}
void Out(vector<ll> x) {REP(i,0,x.size()) {cout<<x[i]<<" ";} cout<<endl;}

class ST
{
    public:
    ll N; vector<ll> ar; vector<ll> p;
    ll neut;
    vector<ll> lazy;

    ll op(ll a, ll b)
    {
        return max(a,b);
    }

    ST(vector<ll> arr)
    {
        neut=-INF;
        N = (ll) 1<<(ll) ceil(log2(arr.size()));
        REP(i,0,arr.size()) {ar.pb(arr[i]);}
        REP(i,arr.size(),N) {ar.pb(neut);}
        REP(i,0,N) {p.pb(0);}
        REP(i,0,N) {p.pb(ar[i]);}
        ll cur = N-1;
        while(cur>0)
        {
            p[cur]=op(p[2*cur],p[2*cur+1]);
            cur--;
        }
        REP(i,0,2*N) {lazy.pb(0LL);}
    }

    ll query(ll a,ll b, ll c, ll x, ll y) //c=current node, starting in 1, a,b=range of query, x,y=range of node c in the array down, x,y from 0 to N-1. query(a,b)->query(a,b,1,0,N-1)
    {
        if(y<a || x>b) {return neut;}
        if(x>=a && y<=b) {return (p[c]+lazy[c]);}
        ll mid=(x+y)/2;
        p[c]+=lazy[c];
        lazy[2*c]+=lazy[c]; lazy[2*c+1]+=lazy[c]; lazy[c]=0;
        if(2*c>=N) {p[2*c]+=lazy[2*c]; p[2*c+1]+=lazy[2*c+1]; lazy[2*c]=0; lazy[2*c+1]=0; ar[2*c-N]=p[2*c]; ar[2*c+1-N]=p[2*c+1];}
        return op(query(a,b,2*c,x,mid),query(a,b,2*c+1,mid+1,y));
    }

    void update(ll s, ll a, ll b, ll c, ll x, ll y) //positions in [a,b] from 0 to N-1 gets +s
    {
        if(y<a || x>b) {return ;}
        if(x>=a && y<=b)
        {
            lazy[c]+=s;
            if(c>=N) {p[c]+=lazy[c]; lazy[c]=0; ar[c-N]=p[c];}
            return;
        }
        ll mid=(x+y)/2;
        update(s,a,b,2*c,x,mid); update(s,a,b,2*c+1,mid+1,y);
        p[c]=max(p[2*c]+lazy[2*c],p[2*c+1]+lazy[2*c+1]);
    }
};

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll N,Q; cin>>N>>Q;
    string s; vector<ll> a; cin>>s;
    REP(i,0,N)
    {
        if(s[i]=='4') {a.pb(0LL);}
        else {a.pb(1LL);}
    }
    vector<ll> xx; REP(i,0,N) {xx.pb(0LL);}
    ST S(xx);
    REP(i,0,N)
    {
        if(a[i]==0) {S.update(1,i,S.N-1,1,0,S.N-1);}
        else if(i>0) {S.update(1,0,i-1,1,0,S.N-1);}
    }
    string com; ll val1,val2;
    REP(i,0,Q)
    {
        cin>>com;
        if(com=="switch")
        {
            cin>>val1>>val2; val1--; val2--;
            if(val1>val2) {swap(val1,val2);}
            ll dif1=a[val2]-a[val1]; ll dif2=-dif1;
            S.update(-dif1,val1,S.N-1,1,0,S.N-1);
            S.update(dif1,0,val1-1,1,0,S.N-1);
            S.update(-dif2,val2,S.N-1,1,0,S.N-1);
            S.update(dif2,0,val2-1,1,0,S.N-1);
            ll indiferent=a[val1]; a[val1]=a[val2]; a[val2]=indiferent;
        }
        else
        {
            cout<<S.query(0,S.N-1,1,0,S.N-1)<<"\n";
        }
        REP(i,0,N) {cout<<S.query(i,i,1,0,S.N-1)<<" ";}
        cout<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define F first
#define S second
#define pb push_back
const ll N = 1e6 + 10, M = 1e5 + 10, MOD =  1e9 + 7, INF = 1e9 + 10;
const long double PI = acos(-1);
struct Seg{
    bool lazy;
    int c4, c7, lds, lis;
} seg[4 * N];
int n, q;
string s;
void xD(int x){
    seg[x].c4 = seg[x * 2].c4 + seg[x * 2 + 1].c4;
    seg[x].c7 = seg[x * 2].c7 + seg[x * 2 + 1].c7;
    seg[x].lis = max(seg[x * 2].c4 + seg[x * 2 + 1].lis, seg[x * 2].lis + seg[x * 2 + 1].c7);
    seg[x].lds = max(seg[x * 2].c7 + seg[x * 2 + 1].lds, seg[x * 2].lds + seg[x * 2 + 1].c4);
    return;
}
void Build(int b = 0, int e = n, int ind = 1){
    if (b + 1 == e){
        seg[ind].c4 = (s[b] == '4');
        seg[ind].c7 = (s[b] == '7');
        seg[ind].lis = seg[ind].lds = 1;
        return;
    }
    int mid = (b + e) / 2;
    Build(b, mid, ind * 2);
    Build(mid, e, ind * 2 + 1);
    xD(ind);
    return;
}
void Rev(int x){
    seg[x].lazy = 0;
    swap(seg[x].c4, seg[x].c7);
    swap(seg[x].lis, seg[x].lds);
    return;
}
void Shift(int x){
    if (!seg[x].lazy) return;
    Rev(x);
    if (x * 2 < 4 * N) seg[x * 2].lazy ^= 1;
    if (x * 2 + 1 < 4 * N) seg[x * 2 + 1].lazy ^= 1;
    return;
}
void Add(int l, int r, int b = 0, int e = n, int ind = 1){
    Shift(ind);
    if(r <= b || e <= l) return;
    if (l <= b && e <= r){
        seg[ind].lazy ^= 1;
        Shift(ind);
        return;
    }
    int mid = (b + e) / 2;
    Add(l, r, b, mid, ind * 2);
    Add(l, r, mid, e, ind * 2 + 1);
    xD(ind);
    return;
}
int main(){
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> q;
    cin >> s;
    Build();
    cout.flush();
    while (q --){
        string type;
        cin >> type;
        if (type == "count"){
            cout << seg[1].lis << '\n';
        }
        else {
            int l, r;
            cin >> l >> r;
            Add(l - 1, r);
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define F first
#define S second
#define pb push_back
const ll N = 1e6 + 10, M = 1e5 + 10, MOD =  1e9 + 7, INF = 1e9 + 10;
const long double PI = acos(-1);
struct Seg{
    bool lazy;
    int c4, c7, lds, lis;
} seg[4 * N];
int n, q;
string s;
void xD(int x){
    seg[x].c4 = seg[x * 2].c4 + seg[x * 2 + 1].c4;
    seg[x].c7 = seg[x * 2].c7 + seg[x * 2 + 1].c7;
    seg[x].lis = max(seg[x * 2].c4 + seg[x * 2 + 1].lis, seg[x * 2].lis + seg[x * 2 + 1].c7);
    seg[x].lds = max(seg[x * 2].c7 + seg[x * 2 + 1].lds, seg[x * 2].lds + seg[x * 2 + 1].c4);
    return;
}
void Build(int b = 0, int e = n, int ind = 1){
    if (b + 1 == e){
        seg[ind].c4 = (s[b] == '4');
        seg[ind].c7 = (s[b] == '7');
        seg[ind].lis = seg[ind].lds = 1;
        return;
    }
    int mid = (b + e) / 2;
    Build(b, mid, ind * 2);
    Build(mid, e, ind * 2 + 1);
    xD(ind);
    return;
}
void Rev(int x){
    seg[x].lazy = 0;
    swap(seg[x].c4, seg[x].c7);
    swap(seg[x].lis, seg[x].lds);
    return;
}
void Shift(int x){
    if (!seg[x].lazy) return;
    Rev(x);
    seg[x * 2].lazy ^= 1;
    seg[x * 2 + 1].lazy ^= 1;
    return;
}
void Add(int l, int r, int b = 0, int e = n, int ind = 1){
    Shift(ind);
    if(r <= b || e <= l) return;
    if (l <= b && e <= r){
        seg[ind].lazy ^= 1;
        Shift(ind);
        return;
    }
    int mid = (b + e) / 2;
    Add(l, r, b, mid, ind * 2);
    Add(l, r, mid, e, ind * 2 + 1);
    xD(ind);
    return;
}
int main(){
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> q;
    cin >> s;
    Build();
    cout.flush();
    while (q --){
        string type;
        cin >> type;
        if (type == "count"){
            cout << seg[1].lis << '\n';
        }
        else {
            int l, r;
            cin >> l >> r;
            Add(l - 1, r);
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define F first
#define S second
#define pb push_back
const ll N = 1e6 + 10, M = 1e5 + 10, MOD =  1e9 + 7, INF = 1e9 + 10;
const long double PI = acos(-1);
struct Seg{
    bool lazy;
    int c4, c7, lds, lis;
} seg[4 * N];
int n, q;
string s;
void xD(int x){
    seg[x].c4 = seg[x * 2].c4 + seg[x * 2 + 1].c4;
    seg[x].c7 = seg[x * 2].c7 + seg[x * 2 + 1].c7;
    seg[x].lis = max(seg[x * 2].c4 + seg[x * 2 + 1].lis, seg[x * 2].lis + seg[x * 2 + 1].c7);
    seg[x].lds = max(seg[x * 2].c7 + seg[x * 2 + 1].lds, seg[x * 2].lds + seg[x * 2 + 1].c4);
    return;
}
void Build(int b = 0, int e = n, int ind = 1){
    if (b + 1 == e){
        seg[ind].c4 = (s[b] == '4');
        seg[ind].c7 = (s[b] == '7');
        seg[ind].lis = seg[ind].lds = 1;
        return;
    }
    int mid = (b + e) / 2;
    Build(b, mid, ind * 2);
    Build(mid, e, ind * 2 + 1);
    xD(ind);
    return;
}
void bede(int x){
    seg[x].lazy = 0;
    swap(seg[x].c4, seg[x].c7);
    swap(seg[x].lis, seg[x].lds);
    seg[x * 2].lazy ^= 1;
    seg[x * 2 + 1].lazy ^= 1;
    return;
}
void Add(int l, int r, int b = 0, int e = n, int ind = 1){
    if (seg[ind].lazy) bede(ind);
    if (l <= b && e <= r){
        bede(ind);
        return;
    }
    int mid = (b + e) / 2;
    if (l < mid){
        Add(l, r, b, mid, ind * 2);
    }
    if (mid < r){
        Add(l, r, mid, e, ind * 2 + 1);
    }
    xD(ind);
}
int main(){
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> q;
    cin >> s;
    Build();
    while (q --){
        string type;
        cin >> type;
        if (type == "count"){
            cout << ":* " << seg[1].lis << '\n';
        }
        else {
            int l, r;
            cin >> l >> r;
            Add(l - 1, r);
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define F first
#define S second
#define pb push_back
const ll N = 1e6 + 10, M = 1e5 + 10, MOD =  1e9 + 7, INF = 1e9 + 10;
const long double PI = acos(-1);
struct Seg{
    bool lazy;
    int c4, c7, lds, lis;
} seg[4 * N];
int n, q;
string s;
void xD(int x){
    seg[x].c4 = seg[x * 2].c4 + seg[x * 2 + 1].c4;
    seg[x].c7 = seg[x * 2].c7 + seg[x * 2 + 1].c7;
    seg[x].lis = max(seg[x * 2].c4 + seg[x * 2 + 1].lis, seg[x * 2].lis + seg[x * 2 + 1].c7);
    seg[x].lds = max(seg[x * 2].c7 + seg[x * 2 + 1].lds, seg[x * 2].lds + seg[x * 2 + 1].c4);
    return;
}
void Build(int b = 0, int e = n, int ind = 1){
    if (b + 1 == e){
        seg[ind].c4 = (s[b] == '4');
        seg[ind].c7 = (s[b] == '7');
        seg[ind].lis = seg[ind].lds = 1;
        return;
    }
    int mid = (b + e) / 2;
    Build(b, mid, ind * 2);
    Build(mid, e, ind * 2 + 1);
    xD(ind);
    return;
}
void bede(int x){
    seg[x].lazy = 0;
    swap(seg[x].c4, seg[x].c7);
    swap(seg[x].lis, seg[x].lds);
    seg[x * 2].lazy ^= 1;
    seg[x * 2 + 1].lazy ^= 1;
    return;
}
void Add(int l, int r, int b = 0, int e = n, int ind = 1){
    if (seg[ind].lazy) bede(ind);
    if (l <= b && e <= r){
        bede(ind);
        return;
    }
    int mid = (b + e) / 2;
    if (l < mid){
        Add(l, r, b, mid, ind * 2);
    }
    if (mid < r){
        Add(l, r, mid, e, ind * 2 + 1);
    }
    xD(ind);
}
int main(){
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> q;
    cin >> s;
    Build();
    while (q --){
        string type;
        cin >> type;
        if (type == "count"){
            cout << seg[1].lis << '\n';
        }
        else {
            int l, r;
            cin >> l >> r;
            Add(l - 1, r);
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <algorithm>
#include <unordered_map>
#define int                long long
#define pb                 push_back
#define pi                 pair<int,int>
#define vi                 vector<int>
#define all(v)             v.begin(),v.end()
#define MOD                1000000007
#define F                  first
#define S                  second
#define FOR(i,r)           for(int i=0;i<r;i++)
#define REP(i,l,r)         for(int i=l;i<r;i++)
#define RER(i,l,r)         for(int i=l;i>=r;i--)
#define print(v)           for(auto i : v)cout << i << ' ';
#define FASTIO             ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mem(arr,k)         memset(arr,k,sizeof(arr));
#define pii                acos(-1.0)
#define PI                 3.1415926535897932385
#define Sin(a)             sin((pi*a)/180)
#define test()             int x;cin >> x;while(x--){solve();}
#define test2()            int x;cin >> x;for(int i=1;i<=x;i++){cout << "Case #" << i << " : ";solve();}
#define watch(x)           cout << (#x) << " is " << (x) << endl
using namespace std;

/* Mathematical Functions */
int power(int x,int y);
bool isPrime(int n);
int modInv(int a,int b);
int gcdExtended(int a,int b,int *x,int* y);
int mpower(int a,int b,int p);

const int inf = (int)1e17;
const int N = (int)3e5+5;
class node{
	public:
		int zer,one,zo,oz;
};
node tree[N];
int lazy[N];
string str;
void build(int ss,int se,int i){
	if(ss == se){
		tree[i].zo = tree[i].oz = tree[i].zer = tree[i].one = 0;
		if(str[ss] == '0')
			tree[i].zer++;
		else
			tree[i].one++;
		return;
	}
	int mid = (ss+se)/2;
	build(ss,mid,2*i);
	build(mid+1,se,2*i+1);
	tree[i].zer = tree[2*i].zer+tree[2*i+1].zer;
	tree[i].one = tree[2*i].one+tree[2*i+1].zer;
	if(str[mid] == '0' && str[mid+1] == '1'){
		tree[i].zo = tree[2*i].zer + tree[2*i+1].one;
		tree[i].zo = max(tree[2*i].zo,tree[i].zo);
		tree[i].zo = max(tree[2*i+1].zo,tree[i].zo);
	}
	else{
		tree[i].oz = tree[2*i].one + tree[2*i+1].zer;
		tree[i].oz = max(tree[2*i].oz,tree[i].oz);
		tree[i].oz = max(tree[2*i+1].oz,tree[i].oz);
	}
}
void update(int ss,int se,int l,int r,int i)
{
	if(lazy[i]!=0){
		swap(tree[i].zer,tree[i].one);
		swap(tree[i].zo,tree[i].oz);
		if(str[ss] == '0'){
			str[ss] = '1';
		}
		else
			str[ss] = '0';
		if(str[se] == '1'){
			str[se] = '0';
		}
		else
			str[se] = '1';
		lazy[2*i]++;
		lazy[2*i+1]++;
		lazy[2*i]%=2;
		lazy[2*i+1]%=2;
	}
	if(l > se || r < ss){
		return;
	}
	if(l <= ss && r >= se){
		swap(tree[i].zer,tree[i].one);
		swap(tree[i].zo,tree[i].oz);
		if(str[ss] == '0'){
			str[ss] = '1';
		}
		else
			str[ss] = '0';
		if(str[se] == '1'){
			str[se] = '0';
		}
		else
			str[se] = '1';
		lazy[2*i]++;
		lazy[2*i+1]++;
		lazy[2*i]%=2;
		lazy[2*i+1]%=2;
		return;
	}
	int mid = (ss+se)/2;
	update(ss,mid,l,r,2*i);
	update(mid+1,se,l,r,2*i+1);
	tree[i].zer = tree[2*i].zer+tree[2*i+1].zer;
	tree[i].one = tree[2*i].one+tree[2*i+1].zer;
	if(str[mid] == '0' && str[mid+1] == '1'){
		tree[i].zo = tree[2*i].zer + tree[2*i+1].one;
		tree[i].zo = max(tree[2*i].zo,tree[i].zo);
		tree[i].zo = max(tree[2*i+1].zo,tree[i].zo);
	}
	else{
		tree[i].oz = tree[2*i].one + tree[2*i+1].zer;
		tree[i].oz = max(tree[2*i].oz,tree[i].oz);
		tree[i].oz = max(tree[2*i+1].oz,tree[i].oz);
	}
}

int32_t main(){

	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
	FASTIO;
	int n,m;
	cin >> n >> m;
	cin >> str;
	REP(i,0,n){
		if(str[i]=='4')
			str[i]='0';
		else
			str[i]='1';
	}
	build(0,n-1,1);
	REP(i,0,m){
		string opt;
		cin >> opt;
		if(opt == "switch"){
			int l,r;
			cin >> l >> r;
			l--;
			r--;
			update(0,n-1,l,r,1);
		}
		else{
			cout << max(tree[1].zer,max(tree[1].one,tree[1].zo)) << endl;
		}
	}
    return 0;

}
int modInv(int a, int m)
{
int x, y;
int g = gcdExtended(a, m, &x, &y);
int res = (x%m + m) % m;
return res;
}

int gcdExtended(int a, int b, int *x, int *y)
{
if (a == 0){
    *x = 0, *y = 1;
    return b;
  }
  int x1, y1;
  int gcd = gcdExtended(b%a, a, &x1, &y1);
  *x = y1 - (b/a) * x1;
  *y = x1;
  return gcd;
}

int mpower(int x, int y, int p)
{
int res = 1;
x = x % p;
while(y > 0){
    if(y & 1) res = (res*x) % p;
      y = y>>1;
      x = (x*x) % p;
    }
    return res;
}
int power(int x, int y)
{
int res = 1;
while (y > 0){
    if (y & 1) res = res*x;
      y = y>>1;
      x = x*x;
    }
    return res;
}

bool isPrime(int n)
{
if (n <= 1)  return false;
  if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
      int p=sqrt(n);
      for(int i=5;i<=p;i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
          return false;
      return true;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <algorithm>
#include <unordered_map>
#define int                long long
#define pb                 push_back
#define pi                 pair<int,int>
#define vi                 vector<int>
#define all(v)             v.begin(),v.end()
#define MOD                1000000007
#define F                  first
#define S                  second
#define FOR(i,r)           for(int i=0;i<r;i++)
#define REP(i,l,r)         for(int i=l;i<r;i++)
#define RER(i,l,r)         for(int i=l;i>=r;i--)
#define print(v)           for(auto i : v)cout << i << ' ';
#define FASTIO             ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mem(arr,k)         memset(arr,k,sizeof(arr));
#define pii                acos(-1.0)
#define PI                 3.1415926535897932385
#define Sin(a)             sin((pi*a)/180)
#define test()             int x;cin >> x;while(x--){solve();}
#define test2()            int x;cin >> x;for(int i=1;i<=x;i++){cout << "Case #" << i << " : ";solve();}
#define watch(x)           cout << (#x) << " is " << (x) << endl
using namespace std;

/* Mathematical Functions */
int power(int x,int y);
bool isPrime(int n);
int modInv(int a,int b);
int gcdExtended(int a,int b,int *x,int* y);
int mpower(int a,int b,int p);

const int inf = (int)1e17;
const int N = (int)3e5+5;
class node{
	public:
		int zer,one,zo,oz;
};
node tree[N];
int lazy[N];
string str;
void build(int ss,int se,int i){
	if(ss == se){
		tree[i].zo = tree[i].oz = tree[i].zer = tree[i].one = 0;
		if(str[ss] == '0')
			tree[i].zer++;
		else
			tree[i].one++;
		return;
	}
	int mid = (ss+se)/2;
	build(ss,mid,2*i);
	build(mid+1,se,2*i+1);
	tree[i].zer = tree[2*i].zer+tree[2*i+1].zer;
	tree[i].one = tree[2*i].one+tree[2*i+1].one;
	tree[i].zo = tree[i].oz = 0;
	if(tree[2*i].zer && tree[2*i+1].one){
		tree[i].zo = tree[2*i].zer +  tree[2*i+1].one;
	}
		tree[i].zo = max(tree[2*i].zo,tree[i].zo);
		tree[i].zo = max(tree[2*i+1].zo,tree[i].zo);
		if(tree[2*i+1].zo != 0 && tree[2*i].zer){
			tree[i].zo = max(tree[i].zo,tree[2*i+1].zo+tree[2*i].zer);
		}
		if(tree[2*i].one && tree[2*i+1].zer){
			tree[i].oz = tree[2*i].one + tree[2*i+1].zer;
		}
		tree[i].oz = max(tree[2*i].oz,tree[i].oz);
		tree[i].oz = max(tree[2*i+1].oz,tree[i].oz);
		if(tree[2*i+1].oz != 0 && tree[2*i].one){
			tree[i].oz = max(tree[i].oz,tree[2*i].one+tree[2*i+1].oz);
		}
}
void update(int ss,int se,int l,int r,int i)
{
	if(lazy[i]!=0){
		if(lazy[i]&1){
		swap(tree[i].zer,tree[i].one);
		swap(tree[i].zo,tree[i].oz);}
		if(ss != se){
		lazy[2*i]++;
		lazy[2*i+1]++;
		}
		lazy[i] = 0;
	}
	if(l > se || r < ss){
		return;
	}
	if(l <= ss && r >= se){

		swap(tree[i].zer,tree[i].one);
		swap(tree[i].zo,tree[i].oz);
		if(ss == se)
			return;
		lazy[2*i]++;
		lazy[2*i+1]++;
		return;
	}
	int mid = (ss+se)/2;
	update(ss,mid,l,r,2*i);
	update(mid+1,se,l,r,2*i+1);
	tree[i].zer = tree[2*i].zer+tree[2*i+1].zer;
	tree[i].one = tree[2*i].one+tree[2*i+1].one;
	tree[i].zo = tree[i].oz = 0;
	if(tree[2*i].zer && tree[2*i+1].one){
		tree[i].zo = tree[2*i].zer +  tree[2*i+1].one;
	}
		tree[i].zo = max(tree[2*i].zo,tree[i].zo);
		tree[i].zo = max(tree[2*i+1].zo,tree[i].zo);
		if(tree[2*i+1].zo != 0 && tree[2*i].zer){
			tree[i].zo = max(tree[i].zo,tree[2*i+1].zo+tree[2*i].zer);
		}
		if(tree[2*i].one && tree[2*i+1].zer){
			tree[i].oz = tree[2*i].one + tree[2*i+1].zer;
		}
		tree[i].oz = max(tree[2*i].oz,tree[i].oz);
		tree[i].oz = max(tree[2*i+1].oz,tree[i].oz);
		if(tree[2*i+1].oz != 0 && tree[2*i].one){
			tree[i].oz = max(tree[i].oz,tree[2*i].one+tree[2*i+1].oz);
		}
}

int32_t main(){

	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
	FASTIO;
	int n,m;
	cin >> n >> m;
	cin >> str;
	mem(lazy,0);
	REP(i,0,n){
		if(str[i]=='4')
			str[i]='0';
		else
			str[i]='1';
	}
	build(0,n-1,1);
	REP(i,0,m){
		string opt;
		cin >> opt;
		if(opt == "switch"){
			int l,r;
			cin >> l >> r;
			l--;
			r--;
			update(0,n-1,l,r,1);
		}
		else{
			cout << max(tree[1].zer,max(tree[1].one,tree[1].zo)) << endl;
		}
	}
    return 0;

}
int modInv(int a, int m)
{
int x, y;
int g = gcdExtended(a, m, &x, &y);
int res = (x%m + m) % m;
return res;
}

int gcdExtended(int a, int b, int *x, int *y)
{
if (a == 0){
    *x = 0, *y = 1;
    return b;
  }
  int x1, y1;
  int gcd = gcdExtended(b%a, a, &x1, &y1);
  *x = y1 - (b/a) * x1;
  *y = x1;
  return gcd;
}

int mpower(int x, int y, int p)
{
int res = 1;
x = x % p;
while(y > 0){
    if(y & 1) res = (res*x) % p;
      y = y>>1;
      x = (x*x) % p;
    }
    return res;
}
int power(int x, int y)
{
int res = 1;
while (y > 0){
    if (y & 1) res = res*x;
      y = y>>1;
      x = x*x;
    }
    return res;
}

bool isPrime(int n)
{
if (n <= 1)  return false;
  if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
      int p=sqrt(n);
      for(int i=5;i<=p;i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
          return false;
      return true;
}