#include <bits/stdc++.h>
const int maxn = 2e5 + 10;
struct qwq {
  int pre[2], suf[2], ans, sum, d, pred, sufd;
} t[maxn * 5];
char S[maxn];
int n, q;
qwq operator+(const qwq &a, const qwq &b) {
  qwq ret;
  ret.pre[0] = std::max(a.pre[0], a.sum + b.pre[0]);
  ret.pre[1] = std::min(a.pre[1], a.sum + b.pre[1]);
  ret.suf[0] = std::max(b.suf[0], b.sum + a.suf[0]);
  ret.suf[1] = std::min(b.suf[1], b.sum + a.suf[1]);
  ret.sum = a.sum + b.sum;
  ret.d = std::max(a.d + b.sum, b.d - a.sum);
  ret.pred = std::max(a.pred, std::max(a.d + b.pre[0], b.pred - a.sum));
  ret.sufd = std::max(b.sufd, std::max(b.d - a.suf[1], a.sufd + b.sum));
  ret.ans = std::max(std::max(a.ans, b.ans),
                     std::max(b.pred - a.suf[1], a.sufd + b.pre[0]));
  return ret;
}
void ins(int o, int l, int r, int pos, int val) {
  if (l == r) {
    if (val == 1) {
      t[o].pre[0] = 1, t[o].pre[1] = 0, t[o].suf[0] = 1, t[o].suf[1] = 0;
      t[o].ans = 1, t[o].sum = 1, t[o].d = t[o].pred = t[o].sufd = 1;
    } else {
      t[o].pre[0] = 0, t[o].pre[1] = -1, t[o].suf[0] = 0, t[o].suf[1] = -1;
      t[o].ans = 1, t[o].sum = -1, t[o].d = t[o].pred = t[o].sufd = 1;
    }
    return;
  }
  int mid = (l + r) >> 1;
  if (pos <= mid)
    ins(o << 1, l, mid, pos, val);
  else
    ins(o << 1 | 1, mid + 1, r, pos, val);
  t[o] = t[o << 1] + t[o << 1 | 1];
  return;
}
int get(char ch) { return ch == '(' ? 1 : -1; }
int main() {
  scanf("%d%d", &n, &q);
  n = (n - 1) << 1;
  scanf("%s", S + 1);
  for (int i = 1; i <= n; ++i) {
    int x = (S[i] == '(' ? 1 : -1);
    ins(1, 1, n, i, x);
  }
  printf("%d\n", t[1].ans);
  while (q--) {
    int x, y;
    scanf("%d%d", &x, &y);
    std::swap(S[x], S[y]);
    ins(1, 1, n, x, get(S[x]));
    ins(1, 1, n, y, get(S[y]));
    printf("%d\n", t[1].ans);
  }
  return 0;
}
