#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
int n, q, st[600005];
string s;
int query(int l, int r) {
int ret = 0;
for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
if (l&1) ret = max(ret, st[l++]);
if (r&1) ret = max(ret, st[--r]);
}
return ret;
}
void update(int i, int val) {
for (st[i+=n] = val; i > 1; i >>= 1) {
st[i>>1] = max(st[i], st[i^1]);
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> q >> s;
for (int i = 0; i < n; i++) {
if (s[i] == '0') st[i+n] = inf;
else st[i+n] = 0;
}
for (int i = n-1; i >= 0; i--) st[i] = max(st[i<<1], st[i<<1|1]);
for (int t = 1; t <= q; t++) {
cin >> s;
if (s == "query") {
int a, b; cin >> a >> b;
a--, b--;
cout << max(0, t - query(a, b)) << '\n';
} else {
int u; cin >> u;
u--;
bool on = (st[u+n] != inf);
if (!on) update(u, t);
else update(u, inf);
}
// for (int i = 0; i < n; i++) cout << st[i+n] << ' '; cout << '\n';
}
}