#include <bits/stdc++.h>
using namespace std;
const int N = 200005, MXS = N * 4;
int n, q, laz[MXS], a[MXS], b[MXS], ab[MXS], bc[MXS], abc[MXS];
char A[N];
inline void Upd(int id, int val) {
  laz[id] += val;
  a[id] += val;
  b[id] += val;
  ab[id] -= val;
  bc[id] -= val;
}
inline void Shift(int id) {
  Upd((id << 1), laz[id]);
  Upd((id << 1 ^ 1), laz[id]);
  laz[id] = 0;
}
inline void Merge(int id) {
  a[id] = max(a[(id << 1)], a[(id << 1 ^ 1)]);
  b[id] = min(b[(id << 1)], b[(id << 1 ^ 1)]);
  ab[id] = max({ab[(id << 1)], ab[(id << 1 ^ 1)],
                a[(id << 1)] - b[(id << 1 ^ 1)] - b[(id << 1 ^ 1)]});
  bc[id] = max({bc[(id << 1)], bc[(id << 1 ^ 1)],
                a[(id << 1 ^ 1)] - b[(id << 1)] - b[(id << 1)]});
  abc[id] =
      max({abc[(id << 1)], abc[(id << 1 ^ 1)], ab[(id << 1)] + a[(id << 1 ^ 1)],
           a[(id << 1)] + bc[(id << 1 ^ 1)]});
}
void Add(int le, int ri, int val, int id = 1, int l = 0, int r = n + n + 1) {
  if (ri <= l || r <= le) return;
  if (le <= l && r <= ri) return void(Upd(id, val));
  Shift(id);
  Add(le, ri, val, (id << 1), l, ((l + r) >> 1));
  Add(le, ri, val, (id << 1 ^ 1), ((l + r) >> 1), r);
  Merge(id);
}
int main() {
  scanf("%d%d%s", &n, &q, &A);
  n--;
  for (int i = 0, p = 0; i < n + n; i++) {
    p += (A[i] == '(' ? 1 : -1);
    Add(i + 1, i + 2, p);
  }
  printf("%d\n", abc[1]);
  for (; q; q--) {
    int i, j, v;
    scanf("%d%d", &i, &j);
    if (i > j) swap(i, j);
    if (A[i - 1] == '(')
      v = -2;
    else
      v = 2;
    swap(A[i - 1], A[j - 1]);
    Add(i, j, v);
    printf("%d\n", abc[1]);
  }
  return 0;
}
