#include <bits/stdc++.h>
using namespace std;
int lmx[1600005], rmx[1600005], lmn[1600005], rmn[1600005], sum[1600005],
    lans[1600005], rans[1600005], whans[1600005], mans[1600005];
void upd(int now) {
  sum[now] = sum[now << 1] + sum[now << 1 | 1];
  lmx[now] = max(lmx[now << 1], sum[now << 1] + lmx[now << 1 | 1]);
  rmx[now] = max(rmx[now << 1 | 1], sum[now << 1 | 1] + rmx[now << 1]);
  lmn[now] = min(lmn[now << 1], sum[now << 1] + lmn[now << 1 | 1]);
  rmn[now] = min(rmn[now << 1 | 1], sum[now << 1 | 1] + rmn[now << 1]);
  whans[now] = rmx[now] - lmn[now];
  lans[now] = max(lans[now << 1], max(lans[now << 1 | 1] - sum[now << 1],
                                      whans[now << 1] + lmx[now << 1 | 1]));
  rans[now] = max(rans[now << 1 | 1], max(rans[now << 1] + sum[now << 1 | 1],
                                          whans[now << 1 | 1] - rmn[now << 1]));
  mans[now] = max(max(lans[now << 1 | 1] - rmn[now << 1],
                      rans[now << 1] + lmx[now << 1 | 1]),
                  max(mans[now << 1], mans[now << 1 | 1]));
}
void Insert(int now, int l, int r, int pos, int v) {
  if (l == r) {
    sum[now] = lmx[now] = rmx[now] = lmn[now] = rmn[now] = v;
    lmx[now] = max(lmx[now], 0);
    rmx[now] = max(rmx[now], 0);
    lmn[now] = min(lmn[now], 0);
    rmn[now] = min(rmn[now], 0);
    lans[now] = rans[now] = whans[now] = mans[now] = 1;
    return;
  }
  int mid = (l + r) >> 1;
  if (pos <= mid)
    Insert(now << 1, l, mid, pos, v);
  else
    Insert(now << 1 | 1, mid + 1, r, pos, v);
  upd(now);
}
int a[1600005];
void Build(int now, int l, int r) {
  if (l == r) {
    sum[now] = lmx[now] = rmx[now] = lmn[now] = rmn[now] = a[l];
    lmx[now] = max(lmx[now], 0);
    rmx[now] = max(rmx[now], 0);
    lmn[now] = min(lmn[now], 0);
    rmn[now] = min(rmn[now], 0);
    lans[now] = rans[now] = whans[now] = mans[now] = 1;
    return;
  }
  int mid = (l + r) >> 1;
  Build(now << 1, l, mid), Build(now << 1 | 1, mid + 1, r);
  upd(now);
}
int n, q;
char s[1600005];
int main() {
  scanf("%d%d", &n, &q);
  scanf("%s", s + 1);
  for (int i = 1; i <= 2 * n - 2; i++)
    if (s[i] == '(')
      a[i] = 1;
    else
      a[i] = -1;
  Build(1, 1, 2 * n - 2);
  printf("%d\n", mans[1]);
  for (int u, v; q--;) {
    scanf("%d%d", &u, &v);
    swap(a[u], a[v]);
    Insert(1, 1, 2 * n - 2, u, a[u]);
    Insert(1, 1, 2 * n - 2, v, a[v]);
    printf("%d\n", mans[1]);
  }
}
