#include <bits/stdc++.h>
using namespace std;
int a[200000 + 5];
struct SegmentTree {
  int l, r, pre1, pre2, suc1, suc2, val, sum1, sum2;
  SegmentTree() {}
  SegmentTree(int l_, int r_, int pre1_, int pre2_, int suc1_, int suc2_,
              int val_, int sum1_, int sum2_) {
    l = l_;
    r = r_;
    pre1 = pre1_;
    pre2 = pre2_;
    suc1 = suc1_;
    suc2 = suc2_;
    val = val_;
    sum1 = sum1_;
    sum2 = sum2_;
  }
} t[800000 + 5], ans;
void merge(SegmentTree &C, SegmentTree A, SegmentTree B) {
  C.val = max(A.val, B.val);
  C.sum1 = A.sum1;
  C.sum2 = B.sum2;
  if (B.sum1 > A.sum2)
    C.sum1 += B.sum1 - A.sum2;
  else
    C.sum2 += A.sum2 - B.sum1;
  C.pre1 = A.pre1;
  C.pre2 = A.pre2;
  C.suc1 = B.suc1;
  C.suc2 = B.suc2;
  C.pre1 = max(C.pre1, max(A.sum1 + A.sum2 + B.pre2, A.sum1 - A.sum2 + B.pre1));
  C.pre2 = max(C.pre2, A.sum2 - A.sum1 + B.pre2);
  C.suc1 = max(C.suc1, max(A.suc1 + B.sum2 - B.sum1, A.suc2 + B.sum1 + B.sum2));
  C.suc2 = max(C.suc2, A.suc2 + B.sum1 - B.sum2);
  C.val = max(C.val, max(A.suc1 + B.pre2, A.suc2 + B.pre1));
}
void update(int pos) { merge(t[pos], t[pos << 1], t[pos << 1 | 1]); }
void Build(int l, int r, int pos) {
  t[pos].l = l;
  t[pos].r = r;
  if (l == r) {
    if (!a[l])
      t[pos] = SegmentTree(l, r, 1, 1, 1, 0, 1, 0, 1);
    else
      t[pos] = SegmentTree(l, r, 1, 0, 1, 1, 1, 1, 0);
    return;
  }
  int mid = (t[pos].l + t[pos].r) >> 1;
  Build(l, mid, pos << 1);
  Build(mid + 1, r, pos << 1 | 1);
  update(pos);
}
void modify(int id, int pos, int s) {
  if (t[pos].l >= id && t[pos].r <= id) {
    if (!s)
      t[pos] = SegmentTree(id, id, 1, 1, 1, 0, 1, 0, 1);
    else
      t[pos] = SegmentTree(id, id, 1, 0, 1, 1, 1, 1, 0);
    return;
  }
  int mid = (t[pos].l + t[pos].r) >> 1;
  if (mid >= id) modify(id, pos << 1, s);
  if (mid < id) modify(id, pos << 1 | 1, s);
  update(pos);
}
string s;
int main() {
  int n, m, i;
  scanf("%d%d", &n, &m);
  n--;
  n *= 2;
  cin >> s;
  for (i = 1; i <= n; i++) a[i] = (s[i - 1] == ')');
  Build(1, n, 1);
  printf("%d\n", t[1].val);
  for (i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    modify(x, 1, a[y]);
    modify(y, 1, a[x]);
    swap(a[x], a[y]);
    printf("%d\n", t[1].val);
  }
}
