#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 9;
char s[N];
struct Node {
  int sum, pmx, lmx, mi, ma, d;
  friend Node operator+(const Node &l, const Node &r) {
    return {
        l.sum + r.sum,
        max(l.pmx, max(r.ma - 2 * l.mi + l.sum, r.pmx - l.sum)),
        max(l.lmx, max(r.lmx - l.sum, l.ma - 2 * r.mi - 2 * l.sum)),
        min(l.mi, r.mi + l.sum),
        max(l.ma, r.ma + l.sum),
        max(max(l.d, r.d), max(l.ma + r.pmx - l.sum, l.lmx + l.sum + r.ma))};
  }
} v[N * 4];
void build(int l, int r, int x = 1) {
  if (l == r) {
    r = s[l] == '(' ? 1 : -1, v[x] = {r, -r, -r, r, r, 0};
    return;
  }
  int m = l + r >> 1;
  build(l, m, x << 1);
  build(m + 1, r, x << 1 | 1);
  v[x] = v[x << 1] + v[x << 1 | 1];
}
void update(int l, int r, int p, int x = 1) {
  if (l == r) return build(l, r, x);
  int m = l + r >> 1;
  if (p <= m)
    update(l, m, p, x << 1);
  else
    update(m + 1, r, p, x << 1 | 1);
  v[x] = v[x << 1] + v[x << 1 | 1];
}
int main() {
  int n, m, x, y;
  scanf("%d%d%s", &n, &m, s + 1);
  build(1, n = n * 2 - 2);
  for (printf("%d\n", v[1].d); m--; printf("%d\n", v[1].d))
    scanf("%d%d", &x, &y), swap(s[x], s[y]), update(1, n, x), update(1, n, y);
}
