#include <bits/stdc++.h>
using ll = int;
const long long mod = 1e12 + 7;
const ll N = 2e5 + 5;
const int base = 400;
using ull = unsigned long long;
using namespace std;
string s, s1, s2, s3;
ll n, m, t, k, T, cnt, u, tong, v, a[N], ans, b[N], lazy[N * 4];
vector<ll> adj[N];
struct data {
  ll pre, nxt, val, mx, mn;
} st[N * 4];
ll pw(ll k, ll n) {
  ll total = 1;
  for (; n; n >>= 1) {
    if (n & 1) total = (total * k) % mod;
    k = (k * k) % mod;
  }
  return total;
}
void down(ll id) {
  if (lazy[id] == 0) return;
  lazy[id * 2] += lazy[id];
  lazy[id * 2 + 1] += lazy[id];
  st[id * 2].mn += lazy[id];
  st[id * 2].mx += lazy[id];
  st[id * 2].pre -= lazy[id];
  st[id * 2].nxt -= lazy[id];
  st[id * 2 + 1].mn += lazy[id];
  st[id * 2 + 1].mx += lazy[id];
  st[id * 2 + 1].pre -= lazy[id];
  st[id * 2 + 1].nxt -= lazy[id];
  lazy[id] = 0;
}
void update(ll id, ll l, ll r, ll u, ll v, ll k) {
  if (u <= l && r <= v) {
    lazy[id] += k;
    st[id].mn += k;
    st[id].mx += k;
    st[id].pre -= k;
    st[id].nxt -= k;
    return;
  }
  if (u > r || l > v || u > v) return;
  ll mid = (l + r) / 2;
  down(id);
  update(id * 2, l, mid, u, v, k);
  update(id * 2 + 1, mid + 1, r, u, v, k);
  st[id].mx = max(st[id * 2].mx, st[id * 2 + 1].mx);
  st[id].mn = min(st[id * 2].mn, st[id * 2 + 1].mn);
  st[id].pre = max(st[id * 2].pre, max(st[id * 2 + 1].pre,
                                       st[id * 2].mx - st[id * 2 + 1].mn * 2));
  st[id].nxt = max(st[id * 2].nxt, max(st[id * 2 + 1].nxt,
                                       st[id * 2 + 1].mx - st[id * 2].mn * 2));
  st[id].val = max(max(st[id * 2].val, st[id * 2 + 1].val),
                   max(st[id * 2].pre + st[id * 2 + 1].mx,
                       st[id * 2 + 1].nxt + st[id * 2].mx));
}
void sol() {
  cin >> n >> m >> s;
  n = 2 * n - 2;
  for (int i = 1; i <= n; i++) {
    if (s[i - 1] == '(')
      update(1, 1, n, i, n, 1);
    else
      update(1, 1, n, i, n, -1);
  }
  cout << st[1].val << '\n';
  for (int i = 1; i <= m; i++) {
    cin >> u >> v;
    if (u > v) swap(u, v);
    if (s[u - 1] != s[v - 1]) {
      if (s[u - 1] == '(')
        update(1, 1, n, u, v - 1, -2);
      else
        update(1, 1, n, u, v - 1, 2);
      swap(s[u - 1], s[v - 1]);
    }
    cout << st[1].val << '\n';
  }
}
int main() {
  if (fopen("sequence"
            ".in",
            "r")) {
    freopen(
        "sequence"
        ".in",
        "r", stdin);
    freopen(
        "sequence"
        ".out",
        "w", stdout);
  }
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int ntest;
  ntest = 1;
  while (ntest-- > 0) sol();
}
