#include <bits/stdc++.h>
using namespace std;
int Max[800021], subl[800021], subr[800021], Min[800021], ans[800021],
    lz[800021];
int n, Q, h[800021];
void push_up(int u) {
  int l = u << 1, r = u << 1 | 1;
  ans[u] = max(ans[l], max(ans[r], max(subl[l] + Max[r], subr[r] + Max[l])));
  subl[u] = max(subl[l], max(subl[r], Max[l] - Min[r] * 2));
  subr[u] = max(subr[r], max(subr[l], Max[r] - Min[l] * 2));
  Max[u] = max(Max[l], Max[r]);
  Min[u] = min(Min[l], Min[r]);
}
void push_down(int u) {
  if (lz[u] == 0) return;
  int l = u << 1, r = u << 1 | 1;
  subl[l] -= lz[u], subl[r] -= lz[u];
  subr[l] -= lz[u], subr[r] -= lz[u];
  Max[l] += lz[u], Max[r] += lz[u];
  Min[l] += lz[u], Min[r] += lz[u];
  lz[l] += lz[u], lz[r] += lz[u];
  lz[u] = 0;
}
void update(int u, int l, int r, int x, int y, int add) {
  if (l == x && r == y) {
    subr[u] -= add, subl[u] -= add, Max[u] += add, Min[u] += add, lz[u] += add;
    return;
  }
  int mid = l + r >> 1;
  push_down(u);
  if (x > mid)
    update(u << 1 | 1, mid + 1, r, x, y, add);
  else if (y <= mid)
    update(u << 1, l, mid, x, y, add);
  else
    update(u << 1, l, mid, x, mid, add),
        update(u << 1 | 1, mid + 1, r, mid + 1, y, add);
  push_up(u);
}
void build(int u, int l, int r) {
  if (l == r) {
    Min[u] = Max[u] = h[l];
    subl[u] = subr[u] = -h[l];
    ans[u] = lz[u] = 0;
    return;
  }
  int mid = l + r >> 1;
  build(u << 1, l, mid);
  build(u << 1 | 1, mid + 1, r);
  push_up(u);
}
char s[800021];
int main() {
  scanf("%d%d%s", &n, &Q, s);
  n = 2 * n - 1;
  h[1] = 0;
  for (int i = 0; i < n - 1; i++) {
    h[i + 2] = h[i + 1] + (s[i] == '(' ? 1 : -1);
  }
  build(1, 1, n);
  int a, b;
  printf("%d\n", ans[1]);
  while (Q--) {
    scanf("%d%d", &a, &b);
    if (a > b) swap(a, b);
    swap(s[a - 1], s[b - 1]);
    update(1, 1, n, a + 1, b, s[a - 1] == '(' ? 2 : -2);
    printf("%d\n", ans[1]);
  }
  return 0;
}
