#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 70;
const int INF = 2.1e9;
const int MOD = 1e9 + 7;
const double eps = 1e-7;
const double PI = acos(-1.0);
int n, m, k, Q;
char s[maxn];
int a[maxn], addv[4 * maxn];
struct node {
  int ans, mi, mx, x, y;
} G[4 * maxn];
node merge(node& a, node& b) {
  node c;
  c.mi = min(a.mi, b.mi);
  c.mx = max(a.mx, b.mx);
  c.x = max(max(a.x, b.x), a.mx - 2 * b.mi);
  c.y = max(max(a.y, b.y), b.mx - 2 * a.mi);
  c.ans = max(max(a.ans, b.ans), max(a.mx + b.y, a.x + b.mx));
  return c;
}
void build(int o, int L, int R) {
  if (L == R) {
    G[o] = {0, a[L], a[L], -a[L], -a[L]};
    return;
  } else {
    int M = L + (R - L) / 2;
    int lc = o * 2, rc = o * 2 + 1;
    build(lc, L, M);
    build(rc, M + 1, R);
    G[o] = merge(G[lc], G[rc]);
  }
}
void modify(node& a, int v) {
  a.mi += v;
  a.mx += v;
  a.x -= v;
  a.y -= v;
}
int ql, qr, v;
void update(int o, int L, int R) {
  if (ql <= L && qr >= R) {
    addv[o] += v;
    modify(G[o], v);
  } else {
    int M = L + (R - L) / 2;
    int lc = o * 2, rc = o * 2 + 1;
    if (ql <= M) update(lc, L, M);
    if (qr >= M + 1) update(rc, M + 1, R);
    G[o] = merge(G[lc], G[rc]);
    modify(G[o], addv[o]);
  }
}
void check(int o, int L, int R) {
  cout << L << " --- " << R << ": " << G[o].ans << " " << G[o].mi << " "
       << G[o].mx << " " << G[o].x << " " << G[o].y << endl;
  if (L < R) {
    int M = L + (R - L) / 2;
    int lc = o * 2, rc = o * 2 + 1;
    check(lc, L, M);
    check(rc, M + 1, R);
  }
}
int main() {
  while (cin >> n >> Q) {
    n = 2 * (n - 1);
    scanf("%s", s + 1);
    for (int i = 1; i <= n; i++) {
      if (s[i] == '(')
        a[i] = a[i - 1] + 1;
      else
        a[i] = a[i - 1] - 1;
    }
    build(1, 1, n);
    printf("%d\n", G[1].ans);
    while (Q--) {
      scanf("%d %d", &ql, &qr);
      if (ql > qr) swap(ql, qr);
      if (s[ql] == '(')
        v = -2;
      else
        v = 2;
      swap(s[ql], s[qr]);
      qr--;
      update(1, 1, n);
      printf("%d\n", G[1].ans);
    }
  }
  return 0;
}
