#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100100, INF = 0x3f3f3f;
int n, q, a, b;
char s[2 * MAXN];
struct T {
  int sum, maxPfx, minPfx, k1, k2, k3;
  T(int x = 0) : sum(x), maxPfx(x), minPfx(x), k1(-x), k2(-x), k3(0) {}
  T operator+(const T& o) const {
    T ans;
    ans.sum = sum + o.sum;
    ans.maxPfx = max(maxPfx, sum + o.maxPfx);
    ans.minPfx = min(minPfx, sum + o.minPfx);
    ans.k1 = max(max(k1, o.k1 - sum), maxPfx - 2 * (sum + o.minPfx));
    ans.k2 = max(max(k2, o.k2 - sum), -2 * minPfx + (sum + o.maxPfx));
    ans.k3 =
        max(max(k3, o.k3), max(k1 + (sum + o.maxPfx), maxPfx + (o.k2 - sum)));
    return ans;
  }
};
struct no {
  int beg, end, mid;
  no *l, *r;
  T t;
  no(int beg, int end)
      : beg(beg), end(end), mid((beg + end) >> 1), t(s[beg] == '(' ? 1 : -1) {
    if (beg != end)
      l = new no(beg, mid), r = new no(mid + 1, end), t = l->t + r->t;
  }
  no() {
    if (beg != end) delete l, delete r;
  }
  void upd(int pos) {
    if (beg == end) return void(t = T(-t.sum));
    (pos <= mid ? l : r)->upd(pos);
    t = l->t + r->t;
  }
};
int main() {
  scanf("%d %d %s", &n, &q, s + 1);
  no seg(1, 2 * n - 2);
  printf("%d\n", seg.t.k3);
  while (q--) {
    scanf("%d %d", &a, &b);
    seg.upd(a), seg.upd(b);
    printf("%d\n", seg.t.k3);
  }
}
