#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
double eps = 1e-8;
char ch[210000];
int read() {
  int v = 0, f = 1;
  char c = getchar();
  while (c < 48 || 57 < c) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar();
  return v * f;
}
struct node {
  int t1, t2, t3, t4, t5, t6, t7, t8, t9;
} t[210000 << 2];
node merge(node x, node y) {
  node re;
  if (x.t2 <= y.t1) {
    re.t1 = y.t1 - x.t2 + x.t1;
    re.t2 = y.t2;
  } else {
    re.t1 = x.t1;
    re.t2 = x.t2 - y.t1 + y.t2;
  }
  re.t3 = max(x.t3, max(x.t1 + x.t2 + y.t7, x.t1 - x.t2 + y.t3));
  re.t4 = max(y.t4, max(y.t1 + y.t2 + x.t6, y.t2 - y.t1 + x.t4));
  re.t5 = max(x.t5, x.t1 - x.t2 + y.t5);
  re.t6 = max(y.t6, y.t1 - y.t2 + x.t6);
  re.t7 = max(x.t7, x.t2 - x.t1 + y.t7);
  re.t8 = max(y.t8, y.t2 - y.t1 + x.t8);
  re.t9 = max(max(x.t9, y.t9), max(x.t4 + y.t7, x.t6 + y.t3));
  return re;
}
void build(int l, int r, int p) {
  if (l == r) {
    if (ch[l] == '(')
      t[p] = (node){0, 1, 1, 1, 0, 0, 1, 1, 1};
    else
      t[p] = (node){1, 0, 1, 1, 1, 1, 0, 0, 1};
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, p << 1);
  build(mid + 1, r, p << 1 | 1);
  t[p] = merge(t[p << 1], t[p << 1 | 1]);
}
void update(int l, int r, int x, char y, int p) {
  if (l == r) {
    if (y == '(')
      t[p] = (node){0, 1, 1, 1, 0, 0, 1, 1, 1};
    else
      t[p] = (node){1, 0, 1, 1, 1, 1, 0, 0, 1};
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid)
    update(l, mid, x, y, p << 1);
  else
    update(mid + 1, r, x, y, p << 1 | 1);
  t[p] = merge(t[p << 1], t[p << 1 | 1]);
}
int main() {
  int n = read(), q = read();
  scanf("%s", ch + 1);
  n = strlen(ch + 1);
  build(1, n, 1);
  printf("%d\n", t[1].t9);
  while (q--) {
    int x = read(), y = read();
    update(1, n, x, ch[y], 1);
    update(1, n, y, ch[x], 1);
    swap(ch[x], ch[y]);
    printf("%d\n", t[1].t9);
  }
  return 0;
}
