#include <bits/stdc++.h>
using namespace std;
const int ST_MAX = 1 << 21;
struct SegTree {
  int start;
  int arr[ST_MAX], maxpre[ST_MAX], minsuf[ST_MAX], segalt[ST_MAX],
      prealt[ST_MAX], fulalt[ST_MAX], sufalt[ST_MAX];
  SegTree() {
    start = ST_MAX / 2;
    fill(arr, arr + ST_MAX, 0);
    fill(maxpre, maxpre + ST_MAX, 0);
    fill(minsuf, minsuf + ST_MAX, 0);
    fill(segalt, segalt + ST_MAX, 0);
    fill(prealt, prealt + ST_MAX, 0);
    fill(fulalt, fulalt + ST_MAX, 0);
    fill(sufalt, sufalt + ST_MAX, 0);
  }
  void construct() {
    for (int i = start - 1; i > 0; i--) {
      arr[i] = arr[i * 2] + arr[i * 2 + 1];
      prealt[i] = max(prealt[i * 2], max(fulalt[2 * i] + maxpre[2 * i + 1],
                                         -arr[2 * i] + prealt[2 * i + 1]));
      sufalt[i] = max(sufalt[i * 2 + 1], max(fulalt[2 * i + 1] - minsuf[2 * i],
                                             sufalt[2 * i] + arr[2 * i + 1]));
      minsuf[i] = min(minsuf[i * 2 + 1], minsuf[i * 2] + arr[i * 2 + 1]);
      maxpre[i] = max(maxpre[i * 2], arr[i * 2] + maxpre[i * 2 + 1]);
      fulalt[i] =
          max(fulalt[2 * i] + arr[2 * i + 1], -arr[2 * i] + fulalt[2 * i + 1]);
      segalt[i] = max(max(segalt[i * 2], segalt[i * 2 + 1]),
                      max(sufalt[i * 2] + maxpre[i * 2 + 1],
                          -minsuf[i * 2] + prealt[i * 2 + 1]));
    }
  }
  void add(int i, int val) {
    i += start;
    arr[i] = minsuf[i] = maxpre[i] = prealt[i] = segalt[i] = fulalt[i] =
        sufalt[i] = val;
    i /= 2;
    while (i > 0) {
      arr[i] = arr[i * 2] + arr[i * 2 + 1];
      prealt[i] = max(prealt[i * 2], max(fulalt[2 * i] + maxpre[2 * i + 1],
                                         -arr[2 * i] + prealt[2 * i + 1]));
      sufalt[i] = max(sufalt[i * 2 + 1], max(fulalt[2 * i + 1] - minsuf[2 * i],
                                             sufalt[2 * i] + arr[2 * i + 1]));
      minsuf[i] = min(minsuf[i * 2 + 1], minsuf[i * 2] + arr[i * 2 + 1]);
      maxpre[i] = max(maxpre[i * 2], arr[i * 2] + maxpre[i * 2 + 1]);
      fulalt[i] =
          max(fulalt[2 * i] + arr[2 * i + 1], -arr[2 * i] + fulalt[2 * i + 1]);
      segalt[i] = max(max(segalt[i * 2], segalt[i * 2 + 1]),
                      max(sufalt[i * 2] + maxpre[i * 2 + 1],
                          -minsuf[i * 2] + prealt[i * 2 + 1]));
      i /= 2;
    }
  }
  long long sum() { return segalt[1]; }
};
char s[200050];
SegTree ST;
int main() {
  int N, Q;
  scanf("%d%d", &N, &Q);
  scanf("%s", s);
  for (int i = 0; i < 2 * N - 2; i++)
    ST.arr[ST.start + i] = ST.maxpre[ST.start + i] = ST.minsuf[ST.start + i] =
        ST.segalt[ST.start + i] = ST.prealt[ST.start + i] =
            ST.sufalt[ST.start + i] = ST.fulalt[ST.start + i] =
                ((s[i] == '(') ? 1 : -1);
  ST.construct();
  printf("%lld\n", ST.sum());
  for (int i = 0; i < Q; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--, b--;
    if (ST.arr[a + ST.start] == ST.arr[b + ST.start]) {
      a = a;
    } else {
      ST.add(a, -1 * ST.arr[a + ST.start]);
      ST.add(b, -1 * ST.arr[b + ST.start]);
    }
    printf("%lld\n", ST.sum());
  }
}
