#include <bits/stdc++.h>
const int INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3f;
using namespace std;
const int MAXN = 2e5 + 5;
char str[MAXN];
int n, q;
struct node {
  int maxu, maxuw, maxuwv, maxwv, minw, layer;
  node *l, *r;
  node() : l(NULL), r(NULL) {}
  node& operator=(const node& a) {
    maxu = a.maxu;
    maxuw = a.maxuw;
    maxuwv = a.maxuwv;
    maxwv = a.maxwv;
    minw = a.minw;
    layer = a.layer;
    return *this;
  }
  node operator+(const node& a) const {
    node res;
    res.maxu = max(maxu, layer + a.maxu);
    res.maxuw = max(max(maxuw, a.maxuw - layer), maxu - 2 * (a.minw + layer));
    res.maxuwv = max(max(maxuwv, a.maxuwv),
                     max(maxu + a.maxwv - layer, maxuw + a.maxu + layer));
    res.maxwv = max(max(maxwv, a.maxwv - layer), a.maxu + layer - 2 * minw);
    res.minw = min(minw, layer + a.minw);
    res.layer = layer + a.layer;
    return res;
  }
};
node nodes[MAXN * 2];
int tot = 0;
node* root;
node* newNode() { return &nodes[tot++]; }
void initNode(node* nd, int l) {
  if (str[l] == '(') {
    nd->maxu = 1;
    nd->maxuw = -1;
    nd->maxuwv = 0;
    nd->maxwv = -1;
    nd->minw = 1;
    nd->layer = 1;
  } else if (str[l] == ')') {
    nd->maxu = -1;
    nd->maxuw = 1;
    nd->maxuwv = 0;
    nd->maxwv = 1;
    nd->minw = -1;
    nd->layer = -1;
  } else {
    puts("ERROR");
  }
}
void pushUp(node* nd) { *nd = (*nd->l + *nd->r); }
void build(node* nd = root, int l = 1, int r = n) {
  if (l != r) {
    nd->l = newNode();
    nd->r = newNode();
    int mid = (l + r) / 2;
    build(nd->l, l, mid);
    build(nd->r, mid + 1, r);
    pushUp(nd);
  } else {
    initNode(nd, l);
  }
}
void init() {
  root = newNode();
  build();
}
void modify(int l, node* nd = root, int cl = 1, int cr = n) {
  if (cl == cr) {
    initNode(nd, l);
    return;
  }
  int mid = (cl + cr) / 2;
  if (l <= mid) {
    modify(l, nd->l, cl, mid);
  } else {
    modify(l, nd->r, mid + 1, cr);
  }
  pushUp(nd);
}
int main() {
  scanf("%d%d", &n, &q);
  n = n * 2 - 2;
  scanf("%s", str + 1);
  init();
  printf("%d\n", root->maxuwv);
  while (q--) {
    int a, b;
    scanf("%d%d", &a, &b);
    swap(str[a], str[b]);
    modify(a);
    modify(b);
    printf("%d\n", root->maxuwv);
  }
  return 0;
}
