#include <bits/stdc++.h>
const int N = 4e5 + 54;
int a[N];
struct SGT {
  int ch[N][2], s[N], lmn[N], lmx[N], rmn[N], rmx[N], ld[N], rd[N], d[N],
      ans[N], nc;
  SGT() { nc = 1; }
  void up(int x) {
    x[s] = x[ch][0][s] + x[ch][1][s];
    x[lmn] = std::min(x[ch][0][lmn], x[ch][0][s] + x[ch][1][lmn]);
    x[lmx] = std::max(x[ch][0][lmx], x[ch][0][s] + x[ch][1][lmx]);
    x[rmn] = std::min(x[ch][0][rmn] + x[ch][1][s], x[ch][1][rmn]);
    x[rmx] = std::max(x[ch][0][rmx] + x[ch][1][s], x[ch][1][rmx]);
    x[ld] = std::max({x[ch][0][ld], x[ch][1][ld] - x[ch][0][s],
                      x[ch][0][d] + x[ch][1][lmx]});
    x[rd] = std::max({x[ch][0][rd] + x[ch][1][s], x[ch][1][rd],
                      x[ch][1][d] - x[ch][0][rmn]});
    x[d] = std::max(x[ch][1][d] - x[ch][0][s], x[ch][0][d] + x[ch][1][s]);
    x[ans] =
        std::max({x[ch][0][ans], x[ch][1][ans], x[ch][1][ld] - x[ch][0][rmn],
                  x[ch][0][rd] + x[ch][1][lmx]});
  }
  void put(int x, int y) {
    x[lmx] = x[rmx] = std::max(y, 0);
    x[lmn] = x[rmn] = std::min(y, 0), x[s] = y;
    x[ld] = x[rd] = x[d] = x[ans] = 1;
  }
  void build(int x, int l, int r) {
    if (l == r) return put(x, a[l]);
    build(x[ch][0] = ++nc, l, (l + r) / 2),
        build(x[ch][1] = ++nc, (l + r) / 2 + 1, r), up(x);
  }
  void upd(int x, int l, int r, int i, int y) {
    if (l == r) return a[i] = y, put(x, y);
    (i <= (l + r) / 2 ? upd(x[ch][0], l, (l + r) / 2, i, y)
                      : upd(x[ch][1], (l + r) / 2 + 1, r, i, y)),
        up(x);
  }
} sgt;
int n, q, x, y;
char s[N];
int main() {
  scanf("%d%d%s", &n, &q, s + 1), n = 2 * n - 2;
  for (int i = 1; i <= n; i++) a[i] = s[i] == '(' ? 1 : -1;
  sgt.build(1, 1, n);
  for (printf("%d\n", sgt.ans[1]); q--; printf("%d\n", sgt.ans[1])) {
    scanf("%d%d", &x, &y);
    int p = a[x], q = a[y];
    sgt.upd(1, 1, n, x, q);
    sgt.upd(1, 1, n, y, p);
  }
}
