#include <bits/stdc++.h>
const int MAXN = 3e5 + 10;
const double eps = 1e-8;
const int mod = 1e9 + 9;
using namespace std;
struct edge {
  int t, v;
  edge *next;
} e[MAXN << 1], *h[MAXN], *o = e;
void add(int x, int y, int vul) {
  o->t = y;
  o->v = vul;
  o->next = h[x];
  h[x] = o++;
}
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
typedef struct node {
  int pmx, lmx, sum, ans, maxx, minn;
} node;
node d[MAXN << 2];
char str[MAXN];
void up(int x) {
  d[x].sum = d[x << 1].sum + d[x << 1 | 1].sum;
  d[x].pmx = max(d[x << 1].pmx,
                 max(d[x << 1 | 1].maxx - 2 * d[x << 1].minn + d[x << 1].sum,
                     d[x << 1 | 1].pmx - d[x << 1].sum));
  d[x].lmx = max(d[x << 1].lmx, max(d[x << 1 | 1].lmx - d[x << 1].sum,
                                    d[x << 1].maxx - 2 * d[x << 1 | 1].minn -
                                        2 * d[x << 1].sum));
  d[x].minn = min(d[x << 1].minn, d[x << 1 | 1].minn + d[x << 1].sum);
  d[x].maxx = max(d[x << 1].maxx, d[x << 1 | 1].maxx + d[x << 1].sum);
  d[x].ans =
      max(d[x << 1].ans, max(d[x << 1 | 1].ans, d[x << 1].lmx + d[x << 1].sum +
                                                    d[x << 1 | 1].maxx));
  d[x].ans = max(d[x].ans, d[x << 1].maxx + d[x << 1 | 1].pmx - d[x << 1].sum);
}
int a[MAXN];
void built(int x, int l, int r) {
  if (l == r) {
    if (str[l] == '(')
      a[l] = 1;
    else
      a[l] = -1;
    d[x].ans = 0;
    d[x].minn = d[x].sum = d[x].maxx = a[l];
    d[x].pmx = d[x].lmx = -a[l];
    return;
  }
  int mid = (l + r) >> 1;
  built(x << 1, l, mid);
  built(x << 1 | 1, mid + 1, r);
  up(x);
}
void update(int x, int l, int r, int t, int k) {
  if (l == r) {
    d[x].sum = d[x].maxx = d[x].minn = k;
    d[x].pmx = d[x].lmx = -k;
    d[x].ans = 0;
    return;
  }
  int mid = (l + r) >> 1;
  if (t <= mid)
    update(x << 1, l, mid, t, k);
  else
    update(x << 1 | 1, mid + 1, r, t, k);
  up(x);
}
int main() {
  int n = read();
  int m = read();
  scanf("%s", str + 1);
  built(1, 1, 2 * n - 2);
  printf("%d\n", d[1].ans);
  while (m--) {
    int x = read();
    int y = read();
    swap(a[x], a[y]);
    update(1, 1, 2 * n - 2, x, a[x]);
    update(1, 1, 2 * n - 2, y, a[y]);
    printf("%d\n", d[1].ans);
  }
  return 0;
}
