#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 100;
const int M = maxn << 2;
int xy[M], yz[M], mn[M], mx[M], ans[M], tag[M];
int da[maxn];
void pushUp(int rt) {
  xy[rt] = max(xy[(rt << 1)], xy[(rt << 1 | 1)]);
  xy[rt] = max(xy[rt], mx[(rt << 1)] - mn[(rt << 1 | 1)] * 2);
  yz[rt] = max(yz[(rt << 1)], yz[(rt << 1 | 1)]);
  yz[rt] = max(yz[rt], mx[(rt << 1 | 1)] - mn[(rt << 1)] * 2);
  mx[rt] = max(mx[(rt << 1)], mx[(rt << 1 | 1)]);
  mn[rt] = min(mn[(rt << 1)], mn[(rt << 1 | 1)]);
  ans[rt] = max(ans[(rt << 1)], ans[(rt << 1 | 1)]);
  ans[rt] = max(ans[rt], max(xy[(rt << 1)] + mx[(rt << 1 | 1)],
                             mx[(rt << 1)] + yz[(rt << 1 | 1)]));
}
void pushDn(int rt) {
  if (tag[rt]) {
    xy[(rt << 1)] -= tag[rt];
    yz[(rt << 1)] -= tag[rt];
    mn[(rt << 1)] += tag[rt];
    mx[(rt << 1)] += tag[rt];
    tag[(rt << 1)] += tag[rt];
    xy[(rt << 1 | 1)] -= tag[rt];
    yz[(rt << 1 | 1)] -= tag[rt];
    mn[(rt << 1 | 1)] += tag[rt];
    mx[(rt << 1 | 1)] += tag[rt];
    tag[(rt << 1 | 1)] += tag[rt];
    tag[rt] = 0;
  }
}
void build(int l, int r, int rt) {
  if (l == r) {
    mn[rt] = mx[rt] = da[l];
    xy[rt] = yz[rt] = -da[l];
    ans[rt] = -inf;
  } else {
    build(l, ((l + r) >> 1), (rt << 1));
    build(((l + r) >> 1) + 1, r, (rt << 1 | 1));
    pushUp(rt);
  }
}
void update(int l, int r, int L, int R, int val, int rt) {
  if (L <= l && r <= R) {
    tag[rt] += val;
    mx[rt] += val;
    mn[rt] += val;
    xy[rt] -= val;
    yz[rt] -= val;
  } else {
    pushDn(rt);
    if (L <= ((l + r) >> 1)) update(l, ((l + r) >> 1), L, R, val, (rt << 1));
    if (((l + r) >> 1) < R)
      update(((l + r) >> 1) + 1, r, L, R, val, (rt << 1 | 1));
    pushUp(rt);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  n = (n - 1) * 2;
  for (int i = 0; i < n; i++) {
    if (s[i] == '(')
      da[i + 1] = da[i] + 1;
    else
      da[i + 1] = da[i] - 1;
  }
  build(1, n, 1);
  cout << ans[1] << endl;
  int l, r;
  while (q--) {
    cin >> l >> r;
    update(1, n, l, n, s[l - 1] == '(' ? -2 : 2, 1);
    update(1, n, r, n, s[r - 1] == '(' ? -2 : 2, 1);
    swap(s[l - 1], s[r - 1]);
    cout << ans[1] << endl;
  }
  return 0;
}
