#include <bits/stdc++.h>
using namespace std;
const long long N = 8e5 + 5, mod = 998244353, inf = 1e18;
long long n, q, mx[N], mx1[N], mx2[N], mn[N], res[N], lzy[N];
string s;
void shift(long long v, long long s, long long e) {
  long long mid = (e + s) / 2ll, lc = v + v, rc = lc + 1;
  long long x = lzy[v];
  mx[lc] += x;
  mx1[lc] -= x;
  mx2[lc] -= x;
  mn[lc] += x;
  lzy[lc] += x;
  mx[rc] += x;
  mx1[rc] -= x;
  mx2[rc] -= x;
  mn[rc] += x;
  lzy[rc] += x;
  lzy[v] = 0;
}
void add(long long l, long long r, long long x, long long v = 1,
         long long s = 0, long long e = n) {
  if ((l >= e) || (r <= s)) return;
  if ((l <= s) && (e <= r)) {
    mx[v] += x;
    mx1[v] -= x;
    mx2[v] -= x;
    mn[v] += x;
    lzy[v] += x;
    return;
  }
  if (lzy[v]) shift(v, s, e);
  long long mid = (e + s) / 2ll, lc = v + v, rc = lc + 1;
  add(l, r, x, lc, s, mid);
  add(l, r, x, rc, mid, e);
  mx[v] = max(mx[lc], mx[rc]);
  mx1[v] = max({mx1[lc], mx1[rc], mx[rc] - 2ll * mn[lc]});
  mx2[v] = max({mx2[lc], mx2[rc], mx[lc] - 2ll * mn[rc]});
  mn[v] = min(mn[lc], mn[rc]);
  res[v] = max({res[lc], res[rc], mx1[rc] + mx[lc], mx2[lc] + mx[rc]});
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> q;
  n = n + n - 2;
  cin >> s;
  for (long long i = 0; i < n; i++) {
    if (s[i] == '(')
      add(i, n, 1);
    else
      add(i, n, -1);
  }
  cout << res[1] << "\n";
  while (q--) {
    long long i, j;
    cin >> i >> j;
    i--;
    j--;
    if (s[i] == s[j]) {
      cout << res[1] << "\n";
      continue;
    }
    swap(s[i], s[j]);
    if (s[i] == '(') {
      add(i, n, 2);
      add(j, n, -2);
    } else {
      add(i, n, -2);
      add(j, n, 2);
    }
    cout << res[1] << "\n";
  }
}
