#pragma GCC optimize("O3,unroll-loops")

#include <bits/stdc++.h>

#define endl '\n'

using namespace std;

int n, m;
string s;

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0);
    cin >> n >> m >> s;
    while (m--) {
        int l, r; cin >> l >> r, --l;
        for (int i = l; i < r; ++i)
            s[i] ^= 1;
        int bal = 0;
        for (char c: s)
            bal += (c == '(' ? 1 : -1);
        cout << abs(bal) << endl;
    }
}