#include <bits/stdc++.h>
using namespace std;
const int mn = 2e5 + 10;
char ch[mn];
int deep[mn];
struct TREE {
  int dma, dmi, dab, dbc, dabc;
  int lazy;
} tr[4 * mn];
void pushup(int id) {
  int ls = 2 * id, rs = 2 * id + 1;
  tr[id].dma = max(tr[ls].dma, tr[rs].dma);
  tr[id].dmi = min(tr[ls].dmi, tr[rs].dmi);
  tr[id].dab = max(tr[ls].dab, tr[rs].dab);
  tr[id].dab = max(tr[id].dab, tr[ls].dma - 2 * tr[rs].dmi);
  tr[id].dbc = max(tr[ls].dbc, tr[rs].dbc);
  tr[id].dbc = max(tr[id].dbc, -2 * tr[ls].dmi + tr[rs].dma);
  tr[id].dabc = max(tr[ls].dabc, tr[rs].dabc);
  tr[id].dabc = max(tr[id].dabc, tr[ls].dab + tr[rs].dma);
  tr[id].dabc = max(tr[id].dabc, tr[ls].dma + tr[rs].dbc);
}
void build(int id, int l, int r) {
  if (l == r) {
    tr[id].dma = tr[id].dmi = deep[l];
    tr[id].dab = tr[id].dbc = -deep[l];
    tr[id].dabc = 0;
    return;
  }
  int mid = (l + r) >> 1;
  build(2 * id, l, mid);
  build(2 * id + 1, mid + 1, r);
  pushup(id);
}
void change(int id, int val) {
  tr[id].dma += val, tr[id].dmi += val;
  tr[id].dab -= val, tr[id].dbc -= val;
}
void pushdown(int id) {
  if (tr[id].lazy == 0) return;
  tr[2 * id].lazy += tr[id].lazy;
  tr[2 * id + 1].lazy += tr[id].lazy;
  change(2 * id, tr[id].lazy);
  change(2 * id + 1, tr[id].lazy);
  tr[id].lazy = 0;
}
void update(int id, int l, int r, int L, int R, int val) {
  if (L <= l && r <= R) {
    change(id, val);
    tr[id].lazy += val;
    return;
  }
  int mid = (l + r) >> 1;
  pushdown(id);
  if (R <= mid)
    update(2 * id, l, mid, L, R, val);
  else if (mid + 1 <= L)
    update(2 * id + 1, mid + 1, r, L, R, val);
  else {
    update(2 * id, l, mid, L, mid, val);
    update(2 * id + 1, mid + 1, r, mid + 1, R, val);
  }
  pushup(id);
}
int main() {
  int n, q;
  scanf("%d %d", &n, &q);
  scanf("%s", ch + 1);
  n = n * 2 - 1;
  deep[1] = 0;
  for (int i = 2; i <= n; i++)
    deep[i] = deep[i - 1] + (ch[i - 1] == '(' ? 1 : -1);
  build(1, 1, n);
  printf("%d\n", tr[1].dabc);
  while (q--) {
    int a, b;
    scanf("%d %d", &a, &b);
    if (ch[a] != ch[b]) {
      if (a > b) swap(a, b);
      if (ch[a] == '(')
        update(1, 1, n, a + 1, b, -2);
      else
        update(1, 1, n, a + 1, b, 2);
      swap(ch[a], ch[b]);
    }
    printf("%d\n", tr[1].dabc);
  }
  return 0;
}
