#include <bits/stdc++.h>
using namespace std;
template <typename T>
void chkmin(T &a, T b) {
  a = min(a, b);
}
template <typename T>
void chkmax(T &a, T b) {
  a = max(a, b);
}
inline int fread(void) {
  int ret = 0, op = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') op = -1;
  for (; isdigit(ch); ch = getchar()) ret = (ret << 1) + (ret << 3) - '0' + ch;
  return ret * op;
}
const int MAXN = 4e5 + 10;
const int MAXM = +10;
int n, m;
struct Tuple {
  int val, lm, rm, lp, rp, lt, rt;
  Tuple operator+(const Tuple &b) {
    Tuple ret;
    ret.val = max(max(val, b.val), max(rp + b.lm, rm + b.lp));
    ret.lp = max(lp, max(lt + rt + b.lm, rt - lt + b.lp));
    ret.rp = max(b.rp, max(b.lt + b.rt + rm, b.lt - b.rt + rp));
    ret.lm = max(lm, b.lm - rt + lt);
    ret.rm = max(b.rm, rm - b.lt + b.rt);
    if (lt > b.rt)
      ret.lt = lt + b.lt - b.rt, ret.rt = rt;
    else
      ret.rt = b.rt - lt + rt, ret.lt = b.lt;
    return ret;
  }
} t[MAXN << 2];
int a[MAXN], mx;
void build(int x, int l, int r) {
  if (l == r) {
    t[x].lp = t[x].rp = 1;
    t[x].lm = max(a[l], 0), t[x].rm = max(-a[l], 0);
    t[x].lt = (a[l] == 1), t[x].rt = (a[l] == -1);
    t[x].val = 1;
    return;
  }
  build((x << 1), l, ((l + r) >> 1));
  build((x << 1 | 1), ((l + r) >> 1) + 1, r);
  t[x] = t[(x << 1)] + t[(x << 1 | 1)];
}
void modify(int x, int l, int r, int pos, int tp) {
  if (l > r) return;
  if (l == r) {
    t[x].lp = t[x].rp = 1;
    t[x].lm = max(tp, 0), t[x].rm = max(-tp, 0);
    t[x].lt = (tp == 1), t[x].rt = (tp == -1);
    t[x].val = 1;
    return;
  }
  if (pos <= ((l + r) >> 1))
    modify((x << 1), l, ((l + r) >> 1), pos, tp);
  else
    modify((x << 1 | 1), ((l + r) >> 1) + 1, r, pos, tp);
  t[x] = t[(x << 1)] + t[(x << 1 | 1)];
}
inline void init(void) {
  scanf("%d%d", &n, &m);
  char ch;
  mx = 2 * n - 2;
  for (int i = 1; i <= mx; ++i) {
    cin >> ch;
    if (ch == '(')
      a[i] = 1;
    else
      a[i] = -1;
  }
  build(1, 1, mx);
}
inline void work(void) {
  int x, y;
  printf("%d\n", t[1].val);
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &x, &y);
    modify(1, 1, mx, x, a[y]);
    modify(1, 1, mx, y, a[x]);
    swap(a[x], a[y]);
    printf("%d\n", t[1].val);
  }
}
int main() {
  init();
  work();
  return 0;
}
