#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 5;
int sum[N << 2], ans[N << 2], trans[N << 2], lmin[N << 2], rmin[N << 2],
    lmax[N << 2], rmax[N << 2], pre[N << 2], nxt[N << 2];
void pushup(int p) {
  sum[p] = sum[p << 1] + sum[p << 1 | 1];
  lmin[p] = min(lmin[p << 1], sum[p << 1] + lmin[p << 1 | 1]);
  rmin[p] = min(rmin[p << 1 | 1], sum[p << 1 | 1] + rmin[p << 1]);
  lmax[p] = max(lmax[p << 1], sum[p << 1] + lmax[p << 1 | 1]);
  rmax[p] = max(rmax[p << 1 | 1], sum[p << 1 | 1] + rmax[p << 1]);
  pre[p] = max(pre[p << 1], max(ans[p << 1] + lmax[p << 1 | 1],
                                pre[p << 1 | 1] - sum[p << 1]));
  nxt[p] = max(nxt[p << 1 | 1], max(ans[p << 1 | 1] - rmin[p << 1],
                                    sum[p << 1 | 1] + nxt[p << 1]));
  ans[p] = max(ans[p << 1] + sum[p << 1 | 1], ans[p << 1 | 1] - sum[p << 1]);
  trans[p] =
      max(max(trans[p << 1], trans[p << 1 | 1]),
          max(pre[p << 1 | 1] - rmin[p << 1], nxt[p << 1] + lmax[p << 1 | 1]));
}
char s[N];
void build(int p, int l, int r) {
  if (l == r) {
    int v = s[l - 1] == '(' ? 1 : -1;
    sum[p] = v;
    lmin[p] = rmin[p] = min(v, 0);
    lmax[p] = rmax[p] = max(v, 0);
    pre[p] = nxt[p] = ans[p] = trans[p] = 1;
    return;
  }
  int mid = (l + r) >> 1;
  build(p << 1, l, mid);
  build(p << 1 | 1, mid + 1, r);
  pushup(p);
}
void upt(int p, int l, int r, int pos, int v) {
  if (l == r) {
    sum[p] = v;
    lmin[p] = rmin[p] = min(v, 0);
    lmax[p] = rmax[p] = max(v, 0);
    pre[p] = nxt[p] = ans[p] = trans[p] = 1;
    return;
  }
  int mid = (l + r) >> 1;
  if (pos <= mid)
    upt(p << 1, l, mid, pos, v);
  else
    upt(p << 1 | 1, mid + 1, r, pos, v);
  pushup(p);
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  cin >> s;
  n = (n - 1) << 1;
  build(1, 1, n);
  int o1, o2, v1, v2;
  printf("%d\n", trans[1]);
  while (m--) {
    scanf("%d%d", &o1, &o2);
    if (o1 != o2) swap(s[o1 - 1], s[o2 - 1]);
    v1 = s[o1 - 1] == '(' ? 1 : -1;
    v2 = s[o2 - 1] == '(' ? 1 : -1;
    upt(1, 1, n, o1, v1);
    upt(1, 1, n, o2, v2);
    printf("%d\n", trans[1]);
  }
  return 0;
}
