#include <bits/stdc++.h>
const double esp = 1e-6;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int inf = 1e9;
using namespace std;
long long read() {
  char ch = getchar();
  long long x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int N = 2e5 + 10;
struct node {
  int depth, lmx, rmx, mn, mx, as;
  node operator+(const node a) const {
    node b;
    b.depth = depth + a.depth;
    b.mx = max(mx, a.mx + depth);
    b.mn = min(mn, a.mn + depth);
    b.lmx = max(lmx, a.lmx - depth);
    b.lmx = max(b.lmx, mx - 2 * a.mn - 2 * depth);
    b.rmx = max(rmx, a.rmx - depth);
    b.rmx = max(b.rmx, a.mx - 2 * mn + depth);
    b.as = max(as, a.as);
    b.as = max(b.as, max(lmx + a.mx + depth, a.rmx + mx - depth));
    return b;
  }
} tree[N << 2];
void update(int l, int r, int root, int pos, int val) {
  if (l == r) {
    tree[root].depth = val;
    tree[root].mn = tree[root].mx = val;
    tree[root].lmx = tree[root].rmx = -val;
    tree[root].as = 0;
    return;
  }
  int mid = (l + r) >> 1;
  if (pos <= mid)
    update(l, mid, root << 1, pos, val);
  else
    update(mid + 1, r, root << 1 | 1, pos, val);
  tree[root] = tree[root << 1] + tree[root << 1 | 1];
}
int n, q;
int a, b;
char s[N];
int main() {
  n = read();
  q = read();
  n = 2 * n - 2;
  cin >> s + 1;
  for (int i = 1; i <= n; i++) {
    update(1, n, 1, i, s[i] == '(' ? 1 : -1);
  }
  printf("%d\n", tree[1].as);
  while (q--) {
    a = read(), b = read();
    update(1, n, 1, a, s[b] == '(' ? 1 : -1);
    update(1, n, 1, b, s[a] == '(' ? 1 : -1);
    swap(s[a], s[b]);
    printf("%d\n", tree[1].as);
  }
  return 0;
}
