#include <bits/stdc++.h>
using namespace std;
void read(int &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -f;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  x *= f;
}
void print(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (!x) return;
  print(x / 10), putchar(x % 10 + 48);
}
void write(int x) {
  if (!x)
    putchar('0');
  else
    print(x);
  putchar('\n');
}
const int maxn = 1e6 + 10;
const int inf = 1e9;
const double eps = 1e-8;
const int mod = 1e9 + 7;
struct data {
  int ab, bc, mx, mn, res;
} t[maxn];
int tag[maxn], a[maxn], n, q;
char s[maxn];
void update(int p) {
  t[p].mx = max(t[p << 1].mx, t[p << 1 | 1].mx);
  t[p].mn = min(t[p << 1].mn, t[p << 1 | 1].mn);
  t[p].ab = max(max(t[p << 1].ab, t[p << 1 | 1].ab),
                t[p << 1].mx - t[p << 1 | 1].mn * 2);
  t[p].bc = max(max(t[p << 1].bc, t[p << 1 | 1].bc),
                t[p << 1 | 1].mx - t[p << 1].mn * 2);
  t[p].res = max(
      max(t[p << 1].res, t[p << 1 | 1].res),
      max(t[p << 1].mx + t[p << 1 | 1].bc, t[p << 1].ab + t[p << 1 | 1].mx));
}
void push(int p, int x) {
  t[p].mx += x, t[p].mn += x;
  t[p].ab -= x, t[p].bc -= x;
  tag[p] += x;
}
void pushdown(int p) {
  if (tag[p]) push(p << 1, tag[p]), push(p << 1 | 1, tag[p]), tag[p] = 0;
}
void modify(int p, int l, int r, int x, int y, int v) {
  if (x <= l && r <= y) return push(p, v), void();
  pushdown(p);
  if (x <= ((l + r) >> 1)) modify(p << 1, l, ((l + r) >> 1), x, y, v);
  if (y > ((l + r) >> 1)) modify(p << 1 | 1, ((l + r) >> 1) + 1, r, x, y, v);
  update(p);
}
void build(int p, int l, int r) {
  if (l == r)
    return t[p].mn = t[p].mx = a[l], t[p].ab = t[p].bc = -a[l], void();
  build(p << 1, l, ((l + r) >> 1)), build(p << 1 | 1, ((l + r) >> 1) + 1, r);
  update(p);
}
void debug(int p, int l, int r) {
  if (l == r) {
    printf("%d ", t[p].mn);
  } else
    pushdown(p), debug(p << 1, l, ((l + r) >> 1)),
        debug(p << 1 | 1, ((l + r) >> 1) + 1, r);
}
int main() {
  read(n), read(q);
  n = (n - 1) * 2;
  scanf("%s", s + 1);
  for (int i = 1; i <= n; i++) a[i] = a[i - 1] + (s[i] == '(' ? 1 : -1);
  build(1, 1, n);
  write(t[1].res);
  for (int i = 1; i <= q; i++) {
    int a, b;
    read(a), read(b);
    if (s[a] != s[b]) {
      modify(1, 1, n, a, n, s[a] == '(' ? -2 : 2);
      modify(1, 1, n, b, n, s[b] == '(' ? -2 : 2);
      swap(s[a], s[b]);
    }
    write(t[1].res);
  }
  return 0;
}
