#include <bits/stdc++.h>
using namespace std;
int n, m;
char S[200002];
int s[800002], lmxs[800002], rmns[800002], lm[800002], rm[800002], hm[800002],
    ans[800002];
void Push_Up(int id) {
  s[id] = s[id << 1] + s[id << 1 | 1];
  lmxs[id] = max(lmxs[id << 1], s[id << 1] + lmxs[id << 1 | 1]);
  rmns[id] = min(rmns[id << 1 | 1], s[id << 1 | 1] + rmns[id << 1]);
  lm[id] = max(lm[id << 1], max(hm[id << 1] + lmxs[id << 1 | 1],
                                lm[id << 1 | 1] - s[id << 1]));
  rm[id] = max(rm[id << 1 | 1], max(hm[id << 1 | 1] - rmns[id << 1],
                                    s[id << 1 | 1] + rm[id << 1]));
  hm[id] = max(hm[id << 1] + s[id << 1 | 1], hm[id << 1 | 1] - s[id << 1]);
  ans[id] = max(
      max(ans[id << 1], ans[id << 1 | 1]),
      max(rm[id << 1] + lmxs[id << 1 | 1], lm[id << 1 | 1] - rmns[id << 1]));
}
void Build(int id, int l, int r) {
  if (l == r) {
    s[id] = ((S[l] == '(') ? 1 : -1);
    lmxs[id] = max(s[id], 0);
    rmns[id] = min(s[id], 0);
    lm[id] = rm[id] = hm[id] = ans[id] = 1;
    return;
  }
  int mid = (l + r) >> 1;
  Build(id << 1, l, mid), Build(id << 1 | 1, mid + 1, r);
  Push_Up(id);
}
void Update(int id, int l, int r, int x) {
  if (l == r) {
    s[id] = -s[id];
    lmxs[id] = max(s[id], 0);
    rmns[id] = min(s[id], 0);
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid)
    Update(id << 1, l, mid, x);
  else
    Update(id << 1 | 1, mid + 1, r, x);
  Push_Up(id);
}
int main() {
  scanf("%d%d", &n, &m);
  scanf("%s", S + 1);
  Build(1, 1, 2 * (n - 1));
  printf("%d\n", ans[1]);
  int x, y;
  while (m--) {
    scanf("%d%d", &x, &y);
    if (S[x] != S[y])
      Update(1, 1, 2 * (n - 1), x), Update(1, 1, 2 * (n - 1), y),
          swap(S[x], S[y]);
    printf("%d\n", ans[1]);
  }
  return 0;
}
