#include <bits/stdc++.h>
using namespace std;
int n, q;
struct str {
  int a = 0, b = 0, ab = 0, bc = 0, abc = 0, laz = 0;
} tr[201000 << 2];
char A[201000];
void update(int id, int val) {
  tr[id].laz += val;
  tr[id].a += val;
  tr[id].b += val;
  tr[id].ab -= val;
  tr[id].bc -= val;
}
void shift(int id) {
  update(id << 1, tr[id].laz);
  update(id << 1 ^ 1, tr[id].laz);
  tr[id].laz = 0;
}
void merg(int id) {
  tr[id].a = max(tr[id << 1].a, tr[id << 1 ^ 1].a);
  tr[id].b = min(tr[id << 1].b, tr[id << 1 ^ 1].b);
  tr[id].ab = max({tr[id << 1].ab, tr[id << 1 ^ 1].ab,
                   tr[id << 1].a - 2 * tr[id << 1 ^ 1].b});
  tr[id].bc = max({tr[id << 1].bc, tr[id << 1 ^ 1].bc,
                   tr[id << 1 ^ 1].a - 2 * tr[id << 1].b});
  tr[id].abc = max({tr[id << 1].abc, tr[id << 1 ^ 1].abc,
                    tr[id << 1].ab + tr[id << 1 ^ 1].a,
                    tr[id << 1].a + tr[id << 1 ^ 1].bc});
}
void add(int lt, int rt, int val, int id = 1, int l = 0, int r = n + 3) {
  if (rt <= l || lt >= r) return;
  if (lt <= l && rt >= r) return void(update(id, val));
  shift(id);
  int mid = (l + r) >> 1;
  add(lt, rt, val, id << 1, l, mid);
  add(lt, rt, val, id << 1 ^ 1, mid, r);
  merg(id);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> q;
  cin >> A;
  n = 2 * n - 2;
  for (int i = 0, s = 0; i < n; i++) {
    s += (A[i] == '(' ? 1 : -1);
    add(i + 1, i + 2, s);
  }
  cout << tr[1].abc << endl;
  while (q--) {
    int l, r, v = 2;
    cin >> l >> r;
    if (l > r) swap(l, r);
    if (A[l - 1] == '(') v = -2;
    swap(A[l - 1], A[r - 1]);
    add(l, r, v);
    cout << tr[1].abc << endl;
  }
  return 0;
}
