//MRasool kheyri
//iran -> khorasan -> ferdows -> Baghestan
//14/2/1405
//vasat azmoonima...
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
#define el '\n'
#define mid (l+r)/2
#define lid id<<1
#define rid lid|1
const ll maxn = 2e6 + 100 ;
struct Data{ll sum , lazy;};
ll n , q , a[maxn] , b[maxn] ;
Data node[maxn] ;
void relax(ll l , ll r , ll id){
if(1 < mid-l || a[l]){
node[lid].sum += node[id].lazy ;
node[lid].lazy += node[id].lazy ;
}
if(1 < r-mid || a[mid]){
node[rid].sum += node[id].lazy ;
node[rid].lazy += node[id].lazy ;
}
node[id].lazy = 0 ;
return ;
}
void build(ll l , ll r , ll id){
node[id].lazy = 0 ;
if(l+1 == r){
node[id].sum = 0 ;
return ;
}
build(l,mid,lid) ;
build(mid,r,rid) ;
return;
}
void update(ll s , ll e , ll l , ll r , ll id){
if(e <= l || r <= s){return;}
if(s <= l && r <= e){
a[l] = 1-a[l] ;
return ;
}
relax(l,r,id) ;
update(s,e,l,mid,lid) ;
update(s,e,mid,r,rid) ;
return ;
}
ll get(ll s , ll e , ll l , ll r , ll id){
if(e <= l || r <= s){
return 0 ;
}
if(s <= l && r <= e){
return node[id].sum ;
}
relax(l,r,id) ;
return get(s,e,l,mid,lid) + get(s,e,mid,r,rid) ;
}
void solve(){
cin>>n>>q ;
for(ll i = 0 ; i < n ; i++){
char ch ;
cin>>ch ;
a[i] = ch-'0' ;
}
build(0,n,1) ;
for(ll _ = 0 ; _ < q ; _++){
node[1].lazy++ ;
string s ;
cin>>s ;
if(s == "query"){
ll a , b ;
cin>>a>>b ;
a-- , b-- ;
if(a+1 != b){return;}
cout<<get(a,b,0,n,1)<<el ;
}
else{
ll x ;
cin>>x ;
x-- ;
update(x,x+1,0,n,1) ;
}
}
return ;
}
int main(){
ios_base::sync_with_stdio(0) , cin.tie(nullptr) , cout.tie(nullptr) ;
ll t = 1 ;
//cin>>t ;
while(t--){
solve() ;
}
return 0 ;
}