#include <bits/stdc++.h>
const int N = 2e5 + 5;
int n, q, pos[N];
char s[N];
struct Tree {
  int dt, mn, mx, lv, vr, ans;
  Tree change(int d) const {
    return (Tree){dt + d, mn + d, mx + d, lv - d, vr - d, ans};
  }
  Tree operator+(const Tree &c) const {
    Tree b = c.change(dt), res;
    res = (Tree){b.dt,
                 std::min(mn, b.mn),
                 std::max(mx, b.mx),
                 std::max({lv, b.lv, mx - b.mn * 2}),
                 std::max({vr, b.vr, -mn * 2 + b.mx}),
                 std::max({ans, b.ans, lv + b.mx, mx + b.vr})};
    return res;
  }
} t[N << 2];
const Tree le = (Tree){1, 0, 1, 0, 1, 1}, ri = (Tree){-1, -1, 0, 2, 1, 1};
void build(int u, int l, int r) {
  if (l == r) {
    pos[l] = u;
    t[u] = (s[l] == '(' ? le : ri);
    return;
  }
  int mid = l + r >> 1;
  build(u << 1, l, mid), build(u << 1 | 1, mid + 1, r);
  t[u] = t[u << 1] + t[u << 1 | 1];
}
void modify(int u, int ch) {
  u = pos[u], t[u] = (ch == '(' ? le : ri), u >>= 1;
  while (u) {
    t[u] = t[u << 1] + t[u << 1 | 1];
    u >>= 1;
  }
}
int main() {
  scanf("%d%d%s", &n, &q, s + 1), n = n - 1 << 1;
  build(1, 1, n);
  printf("%d\n", t[1].ans);
  while (q--) {
    int x, y;
    scanf("%d%d", &x, &y);
    modify(x, s[y]), modify(y, s[x]);
    std::swap(s[x], s[y]);
    printf("%d\n", t[1].ans);
  }
  return 0;
}
