#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 50;
int n, q, x, y, num[N];
char c[N];
struct node {
  int l, r, maxn, minn, sum, d1, d2, d3;
  void New() {
    if (c[l] == '(')
      sum = maxn = minn = 1, d2 = d3 = -1, d1 = 0;
    else
      sum = maxn = minn = -1, d2 = d3 = 1, d1 = 0;
  }
  void print() {
    printf("[%d,%d]=={%d %d %d %d %d %d}\n", l, r, maxn, minn, sum, d1, d2, d3);
  }
} t[N * 4];
node merge(node a, node b) {
  node ret;
  ret.l = a.l;
  ret.r = b.r;
  ret.maxn = (a.maxn > a.sum + b.maxn ? a.maxn : a.sum + b.maxn);
  ret.minn = (a.minn < a.sum + b.minn ? a.minn : a.sum + b.minn);
  ret.sum = a.sum + b.sum;
  ret.d1 = ((a.d1 > b.d1 ? a.d1 : b.d1) >
                    (a.d2 + a.sum + b.maxn > a.maxn + b.d3 - a.sum
                         ? a.d2 + a.sum + b.maxn
                         : a.maxn + b.d3 - a.sum)
                ? (a.d1 > b.d1 ? a.d1 : b.d1)
                : (a.d2 + a.sum + b.maxn > a.maxn + b.d3 - a.sum
                       ? a.d2 + a.sum + b.maxn
                       : a.maxn + b.d3 - a.sum));
  ret.d2 = ((a.d2 > b.d2 - a.sum ? a.d2 : b.d2 - a.sum) >
                    a.maxn - 2 * (a.sum + b.minn)
                ? (a.d2 > b.d2 - a.sum ? a.d2 : b.d2 - a.sum)
                : a.maxn - 2 * (a.sum + b.minn));
  ret.d3 = ((a.d3 > b.d3 - a.sum ? a.d3 : b.d3 - a.sum) >
                    -2 * a.minn + b.maxn + a.sum
                ? (a.d3 > b.d3 - a.sum ? a.d3 : b.d3 - a.sum)
                : -2 * a.minn + b.maxn + a.sum);
  return ret;
}
void build(int x, int l, int r) {
  t[x].l = l;
  t[x].r = r;
  if (l == r) {
    num[l] = x;
    t[x].New();
    return;
  }
  int mid = (l + r) >> 1;
  build(x << 1, l, mid);
  build(x << 1 | 1, mid + 1, r);
  t[x] = merge(t[x << 1], t[x << 1 | 1]);
}
void change(int x) {
  x >>= 1;
  while (x) {
    t[x] = merge(t[x << 1], t[x << 1 | 1]);
    x >>= 1;
  }
}
int main() {
  scanf("%d%d%s", &n, &q, c + 1);
  n = 2 * (n - 1);
  build(1, 1, n);
  printf("%d\n", t[1].d1);
  while (q--) {
    scanf("%d%d", &x, &y);
    if (c[x] != c[y]) {
      swap(c[x], c[y]);
      t[num[x]].New();
      t[num[y]].New();
      change(num[x]);
      change(num[y]);
    }
    printf("%d\n", t[1].d1);
  }
  return 0;
}
