#include <iostream>

using namespace std;

int main() {
    const int MAX_LEN = 1000000;
    
    int n, m, i, q, top;
    char str[MAX_LEN + 1];
    int stack[MAX_LEN + 1];
    int match[MAX_LEN + 1];

    while (1) {
        // read a test case
        cin >> n >> m;
        if (!n) break;
        cin >> str + 1;
        
        // find matching parentheses
        top = 0;
        for (i = 1; i <= n; ++i) {
            if (str[i] == '('){
                // push to stack
                stack[++top] = i;
            } else {
                // pop from stack
                match[i] = stack[top--];
                match[match[i]] = i;
                if( top<0 ){
                    cout << "Input error" << endl;
                }
            }
        }
        if( top!=0 ){
            cout << "Input error 2" << endl;
        }
        // output for each query
        for (i = 1; i <= m; ++i) {
            cin >> q;
            cout << match[q] << endl;
        }
        cout << endl;
    }

    return 0;
}

