#include <bits/stdc++.h>
using namespace std;
char getc() {
  char c = getchar();
  while (c != '(' && c != ')') c = getchar();
  return c;
}
int gcd(int n, int m) { return m == 0 ? n : gcd(m, n % m); }
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  return x * f;
}
int n, q, a[200010], L[200010 << 2], R[200010 << 2], sum[200010 << 2],
    tree[200010 << 2][5];
char s[200010];
void update(int k, int x) {
  tree[k][0] = 0;
  tree[k][1] = tree[k][2] = x;
  tree[k][3] = tree[k][4] = -x;
  sum[k] = x;
}
void up(int k) {
  sum[k] = sum[k << 1] + sum[k << 1 | 1];
  tree[k][0] = max(tree[k << 1][0], tree[k << 1 | 1][0]);
  tree[k][0] =
      max(tree[k][0], max(tree[k << 1][3] + sum[k << 1] + tree[k << 1 | 1][1],
                          tree[k << 1][1] - sum[k << 1] + tree[k << 1 | 1][4]));
  tree[k][1] = max(tree[k << 1][1], sum[k << 1] + tree[k << 1 | 1][1]);
  tree[k][2] = min(tree[k << 1][2], sum[k << 1] + tree[k << 1 | 1][2]);
  tree[k][3] = max(max(tree[k << 1][3], tree[k << 1 | 1][3] - sum[k << 1]),
                   tree[k << 1][1] - 2 * (tree[k << 1 | 1][2] + sum[k << 1]));
  tree[k][4] = max(max(tree[k << 1][4], tree[k << 1 | 1][4] - sum[k << 1]),
                   -2 * tree[k << 1][2] + tree[k << 1 | 1][1] + sum[k << 1]);
}
void build(int k, int l, int r) {
  L[k] = l, R[k] = r;
  if (l == r) {
    if (l) update(k, a[l]);
    return;
  }
  int mid = l + r >> 1;
  build(k << 1, l, mid);
  build(k << 1 | 1, mid + 1, r);
  up(k);
}
void modify(int k, int x, int p) {
  if (L[k] == R[k]) {
    update(k, p);
    return;
  }
  int mid = L[k] + R[k] >> 1;
  if (x <= mid)
    modify(k << 1, x, p);
  else
    modify(k << 1 | 1, x, p);
  up(k);
}
signed main() {
  n = read() - 1 << 1, q = read();
  scanf("%s", s + 1);
  for (int i = 1; i <= n; i++)
    if (s[i] == '(')
      a[i] = 1;
    else
      a[i] = -1;
  build(1, 0, n);
  printf("%d\n", tree[1][0]);
  for (int i = 1; i <= q; i++) {
    int x = read(), y = read();
    modify(1, x, a[y]), modify(1, y, a[x]);
    swap(a[x], a[y]);
    printf("%d\n", tree[1][0]);
  }
  return 0;
}
