#include <bits/stdc++.h>
#define fi first
#define se second
#define all(v) v.begin() , v.end()
#define sz(v) int(v.size())
#define unq(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
using namespace std;
typedef long long ll;
typedef pair<int , int> ii;
typedef pair<long long , int> lli;
const int maxN = int(2e6)+7;
int n , m , sum[maxN] , l[maxN] , r[maxN] , t[maxN] , res[maxN];
string s;
void update(int x){
for (; x <= n ; x += x&-x) t[x]++;
}
int get(int x){
int ans = 0;
for (; x >= 1 ; x -= x&-x) ans += t[x];
return ans;
}
void TH1(){
for (int i = 1 ; i <= n ; i++) t[i] = 0;
vector<ii> event , query;
for (int i = 1 ; i <= n ; i++){
sum[i] = sum[i - 1];
if (s[i] == '+') sum[i]++; else sum[i]--;
event.push_back({sum[i] , i});
}
sort(all(event)); reverse(all(event));
for (int i = 1 ; i <= m ; i++){
if (l[i] <= r[i]) query.push_back({sum[l[i] - 1] , i});
}
sort(all(query)); reverse(all(query));
for (int i = 0 , j = -1 ; i < sz(query) ; i++){
while (j + 1 < sz(event) && event[j + 1].fi > query[i].fi){
j++;
update(event[j].se);
}
int id = query[i].se;
res[id] = get(r[id]) - get(l[id] - 1);
}
}
void TH2(){
for (int i = 1 ; i <= n ; i++) t[i] = 0;
for (int i = 1 ; i <= n / 2 ; i++){
swap(s[i] , s[n - i + 1]);
}
vector<ii> event , query;
sum[0] = 0;
for (int i = 1 ; i <= n ; i++){
sum[i] = sum[i - 1];
if (s[i] == '+') sum[i]++; else sum[i]--;
event.push_back({sum[i] , i});
}
sort(all(event)); reverse(all(event));
for (int i = 1 ; i <= m ; i++){
if (l[i] > r[i]){
l[i] = n - l[i] + 1;
r[i] = n - r[i] + 1;
query.push_back({sum[l[i] - 1] , i});
}
}
sort(all(query)); reverse(all(query));
for (int i = 0 , j = -1 ; i < sz(query) ; i++){
while (j + 1 < sz(event) && event[j + 1].fi > query[i].fi){
j++;
update(event[j].se);
}
int id = query[i].se;
res[id] = get(r[id]) - get(l[id] - 1);
}
}
void solve(){
cin >> n >> m >> s;
s = '#' + s;
for (int i = 1 ; i <= m ; i++) cin >> l[i] >> r[i];
TH1();
TH2();
for (int i = 1 ; i <= m ; i++){
cout << res[i] << "\n";
}
}
#define name "A"
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if (fopen(name".INP" , "r")){
freopen(name".INP" , "r" , stdin);
freopen(name".OUT" , "w" , stdout);
}
int t = 1; //cin >> t;
while (t--) solve();
return 0;
}