#include <bits/stdc++.h>
using namespace std;
int n, m;
int A[200005];
struct Segment_Tree {
  int sum[800005], dif[800005], mxl[800005], mxr[800005], mnl[800005],
      mnr[800005], mld[800005], mrd[800005], ald[800005];
  void pushup(int k) {
    int ls = k << 1 | 0;
    int rs = k << 1 | 1;
    sum[k] = sum[ls] + sum[rs];
    mnl[k] = min(mnl[ls], sum[ls] + mnl[rs]);
    mnr[k] = min(mnr[rs], sum[rs] + mnr[ls]);
    mxl[k] = max(mxl[ls], sum[ls] + mxl[rs]);
    mxr[k] = max(mxr[rs], sum[rs] + mxr[ls]);
    ald[k] = max(ald[ls] + sum[rs], ald[rs] - sum[ls]);
    mld[k] = max(mld[ls], max(ald[ls] + mxl[rs], mld[rs] - sum[ls]));
    mrd[k] = max(mrd[rs], max(ald[rs] - mnr[ls], mrd[ls] + sum[rs]));
    dif[k] =
        max(max(dif[ls], dif[rs]), max(mrd[ls] + mxl[rs], mld[rs] - mnr[ls]));
  }
  void build(int k, int l, int r) {
    if (l == r) {
      dif[k] = mld[k] = mrd[k] = ald[k] = 1;
      mxl[k] = mxr[k] = max(0, A[l]);
      mnl[k] = mnr[k] = min(0, A[l]);
      sum[k] = A[l];
      return;
    }
    int mid = l + r >> 1;
    build(k << 1 | 0, l, mid + 0);
    build(k << 1 | 1, mid + 1, r);
    return pushup(k);
  }
  void change(int k, int l, int r, int pos) {
    if (l == r) {
      dif[k] = mld[k] = mrd[k] = ald[k] = 1;
      mxl[k] = mxr[k] = max(0, A[l]);
      mnl[k] = mnr[k] = min(0, A[l]);
      sum[k] = A[l];
      return;
    }
    int mid = l + r >> 1;
    if (pos <= mid)
      change(k << 1 | 0, l, mid + 0, pos);
    else
      change(k << 1 | 1, mid + 1, r, pos);
    return pushup(k);
  }
} T;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int main() {
  n = read() - 1 << 1;
  m = read();
  for (register int i = 1; i <= n; ++i) {
    char op = getchar();
    while (op != '(' && op != ')') op = getchar();
    A[i] = (op == '(' ? +1 : -1);
  }
  T.build(1, 1, n);
  printf("%d\n", T.dif[1]);
  for (register int i = 1; i <= m; ++i) {
    int l = read();
    int r = read();
    if (A[l] != A[r]) {
      swap(A[l], A[r]);
      T.change(1, 1, n, l);
      T.change(1, 1, n, r);
    }
    printf("%d\n", T.dif[1]);
  }
  return 0;
}
