#include <bits/stdc++.h>
using namespace std;
inline int rd() {
  int x = 0;
  char c = getchar();
  while (!isdigit(c)) {
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  return x;
}
inline int max(const int &x, const int &y) { return x < y ? y : x; }
inline int min(const int &x, const int &y) { return x > y ? y : x; }
struct Node {
  int l, r, sum, lmx, rmx;
  int lmn, rmn, ldx, rdx, mdx, mx;
} t[200005 << 2];
int a[200005];
int n, m, x, y, _;
inline void pushup(int p) {
  t[p].sum = t[(p << 1)].sum + t[(p << 1 ^ 1)].sum;
  t[p].lmx = max(t[(p << 1)].lmx, t[(p << 1)].sum + t[(p << 1 ^ 1)].lmx);
  t[p].rmx = max(t[(p << 1 ^ 1)].rmx, t[(p << 1 ^ 1)].sum + t[(p << 1)].rmx);
  t[p].lmn = min(t[(p << 1)].lmn, t[(p << 1)].sum + t[(p << 1)].lmn);
  t[p].rmn = min(t[(p << 1 ^ 1)].rmn, t[(p << 1 ^ 1)].sum + t[(p << 1)].rmn);
  t[p].mdx = max(t[(p << 1 ^ 1)].mdx - t[(p << 1)].sum,
                 t[(p << 1 ^ 1)].sum + t[(p << 1)].mdx);
  t[p].ldx = max(t[(p << 1)].ldx, max(t[(p << 1 ^ 1)].ldx - t[(p << 1)].sum,
                                      t[(p << 1 ^ 1)].lmx + t[(p << 1)].mdx));
  t[p].rdx =
      max(t[(p << 1 ^ 1)].rdx, max(t[(p << 1 ^ 1)].sum + t[(p << 1)].rdx,
                                   t[(p << 1 ^ 1)].mdx - t[(p << 1)].rmn));
  t[p].mx = max(max(t[(p << 1)].mx, t[(p << 1 ^ 1)].mx),
                max(t[(p << 1 ^ 1)].ldx - t[(p << 1)].rmn,
                    t[(p << 1 ^ 1)].lmx + t[(p << 1)].rdx));
}
inline void push(int p, int k) {
  t[p].lmx = t[p].rmx = max(0, k);
  t[p].lmn = t[p].rmn = min(0, k);
  t[p].sum = t[p].ldx = t[p].rdx = t[p].mdx = t[p].mx = k;
}
void build(int l, int r, int p) {
  t[p].l = l, t[p].r = r;
  if (l == r) {
    push(p, a[l]);
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, (p << 1));
  build(mid + 1, r, (p << 1 ^ 1));
  pushup(p);
}
void update(int x, int p = 1) {
  if (t[p].l == t[p].r) {
    push(p, a[x]);
    return;
  }
  update(x, x <= t[(p << 1)].r ? (p << 1) : (p << 1 ^ 1));
  pushup(p);
}
int main() {
  n = rd(), m = rd();
  n = (n - 1) << 1;
  for (int i = 1; i <= n; ++i) {
    a[i] = getchar() == '(' ? 1 : -1;
  }
  build(1, n, 1);
  printf("%d\n", t[1].mx);
  while (m--) {
    x = rd(), y = rd();
    if (a[x] ^ a[y]) {
      _ = a[x], a[x] = a[y], a[y] = _;
      update(x), update(y);
    }
    printf("%d\n", t[1].mx);
  }
  return 0;
}
