#include <bits/stdc++.h>
using std::max;
using std::min;
const int MAXN = 2e5 + 20, MAXSeg = (1 << 19) + 20;
int N = 1;
int val[MAXSeg], sum[MAXSeg];
int pre_max[MAXSeg], suf_min[MAXSeg];
int max_ctrb[MAXSeg], all_ctrb[MAXSeg], pre_ctrb[MAXSeg], suf_ctrb[MAXSeg];
inline void pushup(const int &x) {
  sum[x] = sum[(x << 1)] + sum[((x << 1) | 1)];
  pre_max[x] = max(pre_max[(x << 1)], sum[(x << 1)] + pre_max[((x << 1) | 1)]);
  suf_min[x] =
      min(suf_min[((x << 1) | 1)], sum[((x << 1) | 1)] + suf_min[(x << 1)]);
  all_ctrb[x] = max(sum[x], -sum[x]);
  all_ctrb[x] = max(all_ctrb[x], all_ctrb[(x << 1)] + sum[((x << 1) | 1)]);
  all_ctrb[x] = max(all_ctrb[x], all_ctrb[((x << 1) | 1)] - sum[(x << 1)]);
  pre_ctrb[x] = pre_ctrb[(x << 1)];
  pre_ctrb[x] = max(pre_ctrb[x], all_ctrb[(x << 1)] + pre_max[((x << 1) | 1)]);
  pre_ctrb[x] = max(pre_ctrb[x], pre_ctrb[((x << 1) | 1)] - sum[(x << 1)]);
  suf_ctrb[x] = suf_ctrb[((x << 1) | 1)];
  suf_ctrb[x] = max(suf_ctrb[x], all_ctrb[((x << 1) | 1)] - suf_min[(x << 1)]);
  suf_ctrb[x] = max(suf_ctrb[x], suf_ctrb[(x << 1)] + sum[((x << 1) | 1)]);
  max_ctrb[x] = max(max_ctrb[(x << 1)], max_ctrb[((x << 1) | 1)]);
  max_ctrb[x] = max(max_ctrb[x], suf_ctrb[(x << 1)] + pre_max[((x << 1) | 1)]);
  max_ctrb[x] = max(max_ctrb[x], pre_ctrb[((x << 1) | 1)] - suf_min[(x << 1)]);
}
void modify(const int &pos, const int &Val, const int &nl = 1,
            const int &nr = N, const int &x = 1) {
  if (nl == nr) {
    val[x] = sum[x] = Val;
    pre_max[x] = max(0, val[x]);
    suf_min[x] = min(0, val[x]);
    return;
  }
  int mid = (nl + nr) >> 1;
  if (pos <= mid)
    modify(pos, Val, nl, mid, x << 1);
  else
    modify(pos, Val, mid + 1, nr, (x << 1) | 1);
  pushup(x);
}
inline int read() {
  int x = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (48 ^ c), c = getchar();
  return x;
}
char s[MAXN];
int main() {
  int n = read(), q = read();
  scanf("%s", s);
  n = 2 * n - 2;
  while (N < n) N <<= 1;
  for (int i = N; i < N + n; ++i) {
    if (s[i - N] == '(')
      val[i] = sum[i] = 1;
    else
      val[i] = sum[i] = -1;
    pre_max[i] = max(0, val[i]);
    suf_min[i] = min(0, val[i]);
    pre_ctrb[i] = suf_ctrb[i] = 1;
    max_ctrb[i] = all_ctrb[i] = 1;
  }
  for (int i = N - 1; i; --i) pushup(i);
  printf("%d\n", max_ctrb[1]);
  for (int t = 0; t < q; ++t) {
    int x = read(), y = read();
    if (s[x - 1] == ')') x ^= y ^= x ^= y;
    s[x - 1] = ')';
    modify(x, -1);
    s[y - 1] = '(';
    modify(y, 1);
    printf("%d\n", max_ctrb[1]);
  }
}
