#include <bits/stdc++.h>
using namespace std;
struct zero {
  int sum, prex, prem, sucx, sucm, pred, sucd, d, ans;
  zero() {}
  zero(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8, int p9) {
    sum = p1, prex = p2, prem = p3, sucx = p4, sucm = p5, pred = p6, sucd = p7,
    d = p8, ans = p9;
  }
} tree[200000 << 2];
const zero L = zero(1, 1, 0, 1, 0, 1, 1, 1, 1);
const zero R = zero(-1, 0, -1, 0, -1, 1, 1, 1, 1);
char input[200000];
zero operator+(const zero &a, const zero &b) {
  zero c;
  c.prex = max(a.prex, a.sum + b.prex);
  c.sucx = max(b.sucx, a.sucx + b.sum);
  c.prem = min(a.prem, a.sum + b.prem);
  c.sucm = min(b.sucm, a.sucm + b.sum);
  c.d = max(b.d - a.sum, a.d + b.sum);
  c.pred = max(a.pred, max(b.pred - a.sum, a.d + b.prex));
  c.sucd = max(b.sucd, max(b.sum + a.sucd, b.d - a.sucm));
  c.sum = a.sum + b.sum;
  c.ans = max(max(a.ans, b.ans), max(b.pred - a.sucm, a.sucd + b.prex));
  return c;
}
void build(int x, int l, int r) {
  if (l == r) {
    if (input[l] == '(')
      tree[x] = L;
    else
      tree[x] = R;
    return;
  }
  build((x << 1), l, ((l + r) >> 1)),
      build((x << 1 | 1), ((l + r) >> 1) + 1, r);
  tree[x] = tree[(x << 1)] + tree[(x << 1 | 1)];
}
void update(int x, int l, int r, int pos) {
  if (l == r) {
    if (input[l] == '(')
      tree[x] = L;
    else
      tree[x] = R;
    return;
  }
  if (pos <= ((l + r) >> 1))
    update((x << 1), l, ((l + r) >> 1), pos);
  else
    update((x << 1 | 1), ((l + r) >> 1) + 1, r, pos);
  tree[x] = tree[(x << 1)] + tree[(x << 1 | 1)];
}
int n, m;
int main() {
  scanf("%d%d", &n, &m);
  n = (n - 1) * 2;
  scanf("%s", input + 1);
  build(1, 1, n);
  printf("%d\n", tree[1].ans);
  for (int i = 1; i <= m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    swap(input[a], input[b]);
    update(1, 1, n, a), update(1, 1, n, b);
    printf("%d\n", tree[1].ans);
  }
}
