#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
struct Seg_Tree {
  struct Node {
    int sum;
    int maxdep;
    int mindep;
    int l2m;
    int r2m;
    int lmr;
    Node(int a = 0, int b = 0, int c = 0, int d = 0, int e = 0, int f = 0)
        : sum(a), maxdep(b), mindep(c), l2m(d), r2m(e), lmr(f) {}
    static Node getLeftLef() { return Node(1, 1, 0, 0, 1, 1); }
    static Node getRigLef() { return Node(-1, 0, -1, 2, 1, 1); }
    static Node getEmpLef() { return Node(); }
    Node getShift(int shift) {
      return Node(sum + shift, maxdep + shift, mindep + shift, l2m - shift,
                  r2m - shift, lmr);
    }
  } t[MAXN << 2];
  int n;
  void init(int inputn) {
    for (int i = 0; i < (MAXN << 2); i++) t[i] = Node::getEmpLef();
    n = inputn;
  }
  Node merge(Node &lef, Node &rig) {
    Node nowrig = rig.getShift(lef.sum);
    Node res;
    res.sum = nowrig.sum;
    res.maxdep = max(lef.maxdep, nowrig.maxdep);
    res.mindep = min(lef.mindep, nowrig.mindep);
    res.l2m = max(max(lef.l2m, nowrig.l2m), lef.maxdep - nowrig.mindep * 2);
    res.r2m = max(max(lef.r2m, nowrig.r2m), nowrig.maxdep - lef.mindep * 2);
    res.lmr = max(max(lef.lmr, nowrig.lmr),
                  max(lef.l2m + nowrig.maxdep, nowrig.r2m + lef.maxdep));
    return res;
  }
  void _update(int x, int l, int r, int pos, int ty) {
    if (l == r) {
      if (ty == 1)
        t[x] = Node::getLeftLef();
      else
        t[x] = Node::getRigLef();
      return;
    }
    int mid = (l + r) >> 1;
    if (pos <= mid)
      _update(x << 1, l, mid, pos, ty);
    else
      _update(x << 1 | 1, mid + 1, r, pos, ty);
    t[x] = merge(t[x << 1], t[x << 1 | 1]);
  }
  void update(int pos, int ty) { _update(1, 1, n, pos, ty); }
  int query() { return t[1].lmr; }
} seg;
int n, m;
char s[MAXN];
int main() {
  while (cin >> n >> m) {
    scanf("%s", s + 1);
    n = (n - 1) * 2;
    seg.init(n);
    for (int i = 1; i <= n; i++) {
      if (s[i] == '(')
        seg.update(i, 1);
      else
        seg.update(i, -1);
    }
    printf("%d\n", seg.query());
    while (m--) {
      int l, r;
      scanf("%d%d", &l, &r);
      swap(s[l], s[r]);
      if (s[l] == '(')
        seg.update(l, 1);
      else
        seg.update(l, -1);
      if (s[r] == '(')
        seg.update(r, 1);
      else
        seg.update(r, -1);
      printf("%d\n", seg.query());
    }
  }
}
