#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n, q;
string t;
struct Node {
  int sum, mi, ma, lm, mr, lmr;
  friend Node operator+(const Node &l, const Node &r) {
    return {
        l.sum + r.sum,
        min(l.mi, l.sum + r.mi),
        max(l.ma, l.sum + r.ma),
        max(max(l.lm, r.lm - l.sum), l.ma - 2 * (l.sum + r.mi)),
        max(max(l.mr, r.mr - l.sum), r.ma + l.sum - 2 * l.mi),
        max(max(l.lmr, r.lmr), max(l.ma + r.mr - l.sum, l.lm + l.sum + r.ma))};
  }
} it[N * 4];
void build(int id, int l, int r) {
  if (l == r) {
    int val = (t[l] == '(' ? 1 : -1);
    it[id] = {val, val, val, -val, -val, 0};
    return;
  }
  int mid = l + r >> 1;
  build(id << 1, l, mid);
  build(id << 1 | 1, mid + 1, r);
  it[id] = it[id << 1] + it[id << 1 | 1];
}
void update(int id, int l, int r, int pos) {
  if (l == r) return build(id, l, r);
  int mid = l + r >> 1;
  if (pos <= mid)
    update(id << 1, l, mid, pos);
  else
    update(id << 1 | 1, mid + 1, r, pos);
  it[id] = it[id << 1] + it[id << 1 | 1];
}
int main() {
  if (fopen("exam.inp", "r"))
    freopen("exam.inp", "r", stdin), freopen("exam.out", "w", stdout);
  cin >> n >> q >> t;
  t = " " + t;
  (n *= 2) -= 2;
  build(1, 1, n);
  cout << it[1].lmr << endl;
  while (q--) {
    int x, y;
    cin >> x >> y;
    swap(t[x], t[y]);
    update(1, 1, n, x);
    update(1, 1, n, y);
    cout << it[1].lmr << endl;
  }
}
