#include <bits/stdc++.h>
using namespace std;
inline long long rd() {
  long long _x = 0;
  int _ch = getchar(), _f = 1;
  for (; !isdigit(_ch) && (_ch != '-') && (_ch != EOF); _ch = getchar())
    ;
  if (_ch == '-') {
    _f = 0;
    _ch = getchar();
  }
  for (; isdigit(_ch); _ch = getchar()) _x = _x * 10 + _ch - '0';
  return _f ? _x : -_x;
}
void write(long long _x) {
  if (_x >= 10)
    write(_x / 10), putchar(_x % 10 + '0');
  else
    putchar(_x + '0');
}
inline void wrt(long long _x, char _p) {
  if (_x < 0) putchar('-'), _x = -_x;
  write(_x);
  if (_p) putchar(_p);
}
struct node {
  int L, R, mx, mn, sum, res;
  void add(int x) { L -= x, R -= x, mx += x, mn += x, sum += x; }
};
node push(node A, node B) {
  B.add(A.sum);
  node ans;
  memset(&ans, 0, sizeof(node));
  ans.L = max(A.L, max(B.L, A.mx - 2 * B.mn));
  ans.R = max(A.R, max(B.R, -A.mn * 2 + B.mx));
  ans.sum = B.sum;
  ans.mn = min(A.mn, B.mn), ans.mx = max(A.mx, B.mx);
  ans.res = max(max(A.res, B.res), max(A.L + B.mx, A.mx + B.R));
  return ans;
}
node tr[200005 << 2];
int a[200005];
void update(int pos, int l, int r, int x) {
  if (l == r) {
    tr[pos] = {0, 0, a[x], a[x], a[x], 0};
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid)
    update(pos << 1, l, mid, x);
  else
    update(pos << 1 | 1, mid + 1, r, x);
  tr[pos] = push(tr[pos << 1], tr[pos << 1 | 1]);
}
void build(int pos, int l, int r) {
  if (l == r) {
    tr[pos] = {0, 0, a[l], a[l], a[l], 0};
    return;
  }
  int mid = (l + r) >> 1;
  build(pos << 1, l, mid), build(pos << 1 | 1, mid + 1, r);
  tr[pos] = push(tr[pos << 1], tr[pos << 1 | 1]);
}
int n, q;
char s[200005];
int main() {
  n = (rd() - 1) * 2, q = rd();
  scanf("%s", s + 1);
  for (int i = int(1); i <= (int)(n); i++) a[i] = s[i] == '(' ? 1 : -1;
  build(1, 1, n);
  wrt(tr[1].res, '\n');
  for (int i = int(1); i <= (int)(q); i++) {
    int x = rd(), y = rd();
    swap(a[x], a[y]);
    update(1, 1, n, x), update(1, 1, n, y);
    wrt(tr[1].res, '\n');
  }
}
