#include <bits/stdc++.h>
using namespace std;
struct st {
  int m1, m2, m3, m4, m5, s;
  friend st operator+(st& x, st& y) {
    st r;
    r.m1 = max(x.m1, x.s + y.m1);
    r.m2 = max(x.m2, y.m2 - x.s * 2);
    r.m3 = max({x.m3, y.m3 - x.s, x.m1 + y.m2 - x.s * 2});
    r.m4 = max({x.m4, y.m4 - x.s, x.m2 + y.m1 + x.s});
    r.m5 = max({x.m5, y.m5, x.m3 + y.m1 + x.s, x.m1 + y.m4 - x.s});
    r.s = x.s + y.s;
    return r;
  }
} T[1 << 20];
void upd(int s, int l, int r, int L, int R, int d) {
  if (r < L || R < l) return;
  if (l == r) {
    T[s].m1 += d;
    T[s].m2 -= d * 2;
    T[s].m3 -= d;
    T[s].m4 -= d;
    T[s].s += d;
    return;
  }
  int m = l + r >> 1;
  upd(s * 2, l, m, L, R, d);
  upd(s * 2 + 1, m + 1, r, L, R, d);
  T[s] = T[s * 2] + T[s * 2 + 1];
}
char s[1 << 18];
int main() {
  int n, q;
  scanf("%d %d", &n, &q);
  scanf("%s", s + 1);
  n = n * 2 - 2;
  for (int i = 1; i <= n; ++i) upd(1, 1, n, i, i, s[i] == '(' ? 1 : -1);
  printf("%d\n", T[1].m5);
  while (q--) {
    int a, b;
    scanf("%d %d", &a, &b);
    swap(s[a], s[b]);
    upd(1, 1, n, a, a, s[a] == '(' ? 2 : -2);
    upd(1, 1, n, b, b, s[b] == '(' ? 2 : -2);
    printf("%d\n", T[1].m5);
  }
}
