#include <bits/stdc++.h>
using namespace std;
int n, q, x, y;
char s[100010 << 1];
struct node {
  int sum, rmax, lmax, ans, minn, maxx;
} t[100010 << 3];
void pushup(int x) {
  t[x].sum = t[x << 1].sum + t[x << 1 | 1].sum;
  t[x].rmax = max(t[x << 1].rmax,
                  max(t[x << 1 | 1].rmax - t[x << 1].sum,
                      t[x << 1 | 1].maxx + t[x << 1].sum - 2 * t[x << 1].minn));
  t[x].lmax =
      max(t[x << 1].lmax,
          max(t[x << 1 | 1].lmax - t[x << 1].sum,
              t[x << 1].maxx - 2 * (t[x << 1 | 1].minn + t[x << 1].sum)));
  t[x].ans = max(max(t[x << 1].ans, t[x << 1 | 1].ans),
                 max(t[x << 1 | 1].rmax + t[x << 1].maxx - t[x << 1].sum,
                     t[x << 1].lmax + t[x << 1 | 1].maxx + t[x << 1].sum));
  t[x].minn = min(t[x << 1].minn, t[x << 1 | 1].minn + t[x << 1].sum);
  t[x].maxx = max(t[x << 1].maxx, t[x << 1 | 1].maxx + t[x << 1].sum);
}
void build(int l, int r, int x) {
  int mid = (l + r) >> 1;
  if (l == r) {
    int p = s[l] == '(' ? 1 : -1;
    t[x] = (node){p, -p, -p, 0, p, p};
    return;
  }
  build(l, mid, x << 1);
  build(mid + 1, r, x << 1 | 1);
  pushup(x);
}
void update(int l, int r, int x, int k) {
  int mid = (l + r) >> 1;
  if (l == r) {
    int p = s[l] == '(' ? 1 : -1;
    t[x] = (node){p, -p, -p, 0, p, p};
    return;
  }
  if (k <= mid)
    update(l, mid, x << 1, k);
  else
    update(mid + 1, r, x << 1 | 1, k);
  pushup(x);
}
int main() {
  scanf("%d%d", &n, &q);
  scanf("%s", s + 1);
  n = 2 * n - 2;
  build(1, n, 1);
  printf("%d\n", t[1].ans);
  while (q--) {
    scanf("%d%d", &x, &y);
    swap(s[x], s[y]);
    update(1, n, 1, x);
    update(1, n, 1, y);
    printf("%d\n", t[1].ans);
  }
  return 0;
}
