#include <bits/stdc++.h>
using namespace std;
struct seg {
  int d;
  int min_d, max_d;
  int max_lv;
  int max_rv;
  int max_lvr;
  seg(int d = 0, int min_d = 0, int max_d = 0, int max_lv = 0, int max_rv = 0,
      int max_lvr = 0)
      : d(d),
        min_d(min_d),
        max_d(max_d),
        max_lv(max_lv),
        max_rv(max_rv),
        max_lvr(max_lvr) {}
};
string s;
vector<seg> tree;
seg merge(const seg &l, const seg &r) {
  seg m;
  m.d = l.d + r.d;
  m.min_d = min(l.min_d, r.min_d + l.d);
  m.max_d = max(l.max_d, r.max_d + l.d);
  m.max_lv = max(max(l.max_lv, r.max_lv - l.d), l.max_d - 2 * (r.min_d + l.d));
  m.max_rv = max(max(l.max_rv, r.max_rv - l.d), r.max_d + l.d - 2 * l.min_d);
  m.max_lvr = max(max(l.max_lvr, r.max_lvr),
                  max(l.max_lv + r.max_d + l.d, r.max_rv - l.d + l.max_d));
  return m;
}
void update(int node, int l, int r, int i, char c) {
  if (i < l || i > r) return;
  if (l == r && i == l) {
    if (c == '(') {
      tree[node].d = 1;
      tree[node].min_d = 0;
      tree[node].max_d = 1;
      tree[node].max_lv = 0;
      tree[node].max_rv = 1;
      tree[node].max_lvr = 1;
    } else {
      tree[node].d = -1;
      tree[node].min_d = -1;
      tree[node].max_d = 0;
      tree[node].max_lv = 2;
      tree[node].max_rv = 1;
      tree[node].max_lvr = 1;
    }
  } else {
    int c1 = node * 2 + 1, c2 = node * 2 + 2, m = (l + r) / 2;
    update(c1, l, m, i, c);
    update(c2, m + 1, r, i, c);
    tree[node] = merge(tree[c1], tree[c2]);
  }
}
int main(int argc, char *argv[]) {
  int n, q, k;
  cin >> n >> q >> s;
  for (k = 1; (1 << k) < 2 * n; k++) {
  }
  tree.resize(1 << (k + 1));
  for (int i = 0; i < s.size(); i++) update(0, 0, s.size() - 1, i, s[i]);
  cout << tree[0].max_lvr << endl;
  for (int qi = 0; qi < q; qi++) {
    int a, b;
    cin >> a >> b;
    char c1 = s[a - 1], c2 = s[b - 1];
    if (c1 != c2) {
      s[a - 1] = c2, s[b - 1] = c1;
      update(0, 0, s.size() - 1, a - 1, c2);
      update(0, 0, s.size() - 1, b - 1, c1);
    }
    cout << tree[0].max_lvr << endl;
  }
  return 0;
}
