#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int inf = 0x3f3f3f3f;
struct Node {
  int a, b, c, ab, bc, abc;
  int tag;
} t[N << 2];
char s[N];
int n, q, y[N];
void push_up(int rt) {
  t[rt].a = max(t[rt << 1].a, t[rt << 1 | 1].a);
  t[rt].b = max(t[rt << 1].b, t[rt << 1 | 1].b);
  t[rt].c = max(t[rt << 1].c, t[rt << 1 | 1].c);
  t[rt].ab =
      max({t[rt << 1].ab, t[rt << 1 | 1].ab, t[rt << 1].a + t[rt << 1 | 1].b});
  t[rt].bc =
      max({t[rt << 1].bc, t[rt << 1 | 1].bc, t[rt << 1].b + t[rt << 1 | 1].c});
  t[rt].abc =
      max({t[rt << 1].abc, t[rt << 1 | 1].abc, t[rt << 1].a + t[rt << 1 | 1].bc,
           t[rt << 1].ab + t[rt << 1 | 1].c});
}
void push_down(int rt) {
  if (t[rt].tag) {
    t[rt << 1].tag += t[rt].tag;
    t[rt << 1].a += t[rt].tag;
    t[rt << 1].b -= 2 * t[rt].tag;
    t[rt << 1].c += t[rt].tag;
    t[rt << 1].ab -= t[rt].tag;
    t[rt << 1].bc -= t[rt].tag;
    t[rt << 1 | 1].tag += t[rt].tag;
    t[rt << 1 | 1].a += t[rt].tag;
    t[rt << 1 | 1].b -= 2 * t[rt].tag;
    t[rt << 1 | 1].c += t[rt].tag;
    t[rt << 1 | 1].ab -= t[rt].tag;
    t[rt << 1 | 1].bc -= t[rt].tag;
    t[rt].tag = 0;
  }
}
void build(int l, int r, int rt) {
  t[rt].a = t[rt].b = t[rt].c = -inf;
  t[rt].ab = t[rt].bc = t[rt].abc = -inf;
  t[rt].tag = 0;
  if (l == r) {
    t[rt].a = t[rt].c = y[l];
    t[rt].b = -2 * y[l];
    t[rt].ab = t[rt].a + t[rt].b;
    t[rt].bc = t[rt].b + t[rt].c;
    t[rt].abc = t[rt].a + t[rt].b + t[rt].c;
    return;
  }
  int mid = (l + r) / 2;
  build(l, mid, rt << 1);
  build(mid + 1, r, rt << 1 | 1);
  push_up(rt);
}
void update(int ql, int qr, int k, int l, int r, int rt) {
  if (ql <= l && r <= qr) {
    t[rt].tag += k;
    t[rt].a += k;
    t[rt].b -= 2 * k;
    t[rt].c += k;
    t[rt].ab -= k;
    t[rt].bc -= k;
    return;
  }
  push_down(rt);
  int mid = (l + r) / 2;
  if (ql <= mid) update(ql, qr, k, l, mid, rt << 1);
  if (qr > mid) update(ql, qr, k, mid + 1, r, rt << 1 | 1);
  push_up(rt);
}
int query(int ql, int qr, int l, int r, int rt) {
  if (ql <= l && r <= qr) {
    return t[rt].a;
  }
  push_down(rt);
  int mid = (l + r) / 2, ret = -inf;
  if (ql <= mid) ret = max(ret, query(ql, qr, l, mid, rt << 1));
  if (qr > mid) ret = max(ret, query(ql, qr, mid + 1, r, rt << 1 | 1));
  push_up(rt);
  return ret;
}
int main() {
  scanf("%d%d%s", &n, &q, s + 1);
  n = 2 * n - 2;
  for (int i = 1, x = 0; i <= n; i++) {
    x += s[i] == ')' ? -1 : 1;
    y[i] = x;
  }
  build(0, n, 1);
  printf("%d\n", t[1].abc);
  while (q--) {
    int a, b;
    scanf("%d%d", &a, &b);
    if (a > b) swap(a, b);
    if (s[a] == '(' && s[b] == ')') {
      update(a, b - 1, -2, 0, n, 1);
      swap(s[a], s[b]);
    } else if (s[a] == ')' && s[b] == '(') {
      update(a, b - 1, 2, 0, n, 1);
      swap(s[a], s[b]);
    }
    printf("%d\n", t[1].abc);
  }
  return 0;
}
