#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9;
const long long INF = 1e18;
const long long M = 1e9 + 7;
const long long maxn = 1e6;
struct Seg {
  long long l, r, sum, mx, mn, ab, bc, abc;
} tree[maxn];
long long a[maxn];
void run(long long p) {
  long long lc = p * 2, rc = p * 2 + 1;
  long long base = tree[lc].sum;
  tree[p].sum = base + tree[rc].sum;
  tree[p].mx = max(tree[lc].mx, tree[rc].mx + base);
  tree[p].mn = min(tree[lc].mn, tree[rc].mn + base);
  tree[p].ab = max({tree[lc].ab, tree[rc].ab - base,
                    tree[lc].mx - 2 * (tree[rc].mn + base)});
  tree[p].bc = max(
      {tree[lc].bc, tree[rc].bc - base, -2 * tree[lc].mn + tree[rc].mx + base});
  tree[p].abc =
      max({tree[lc].abc, tree[rc].abc, tree[lc].ab + tree[rc].mx + base,
           tree[lc].mx + tree[rc].bc - base});
}
void init(long long p, long long l, long long r) {
  tree[p].l = l, tree[p].r = r;
  if (l == r) {
    if (a[l] > 0) {
      tree[p] = {l, r, 1, 1, 0, 0, 1, 1};
    } else {
      tree[p] = {l, r, -1, 0, -1, 2, 1, 1};
    }
  } else {
    long long mid = (l + r) / 2;
    init(p * 2, l, mid);
    init(p * 2 + 1, mid + 1, r);
    run(p);
  }
}
void chg(long long p, long long l, long long r, long long x) {
  if (l == r) {
    if (a[l] > 0) {
      tree[p] = {l, r, 1, 1, 0, 0, 1, 1};
    } else {
      tree[p] = {l, r, -1, 0, -1, 2, 1, 1};
    }
  } else {
    long long mid = (l + r) / 2;
    if (mid >= x)
      chg(p * 2, l, mid, x);
    else
      chg(p * 2 + 1, mid + 1, r, x);
    run(p);
  }
}
char s[maxn];
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, q;
  cin >> n >> q;
  n = 2 * (n - 1);
  cin >> (s + 1);
  for (long long i = 1; i <= n; ++i) {
    a[i] = s[i] == '(' ? 1 : -1;
  }
  init(1, 1, n);
  cout << tree[1].abc << endl;
  while (q--) {
    long long l, r;
    cin >> l >> r;
    if (a[l] != a[r]) {
      swap(a[l], a[r]);
      chg(1, 1, n, l);
      chg(1, 1, n, r);
    }
    cout << tree[1].abc << endl;
  }
  return 0;
}
