7 3
1 4 7
1 2 2
2 3 3
3 4 8
2 5 1
1 6 4
6 7 5
 10 2
1 5
5 3 2
8 4 8
7 6 9
7 10 1
10 1 4
9 5 1
5 8 2
7 2 9
6 5 6
 10 5
4 8 7 5 1
5 1 1
2 7 1
4 3 1
10 9 1
10 1 1
1 8 1
10 7 1
10 3 1
7 6 1
 10 9
9 7 6 10 3 5 2 8 1
9 4 10
10 8 3
3 6 2
5 1 8
5 2 5
1 10 10
6 7 1
9 1 7
1 6 3
 10 5
8 5 2 10 1
3 1 7
5 4 6
10 8 4
6 8 9
7 8 4
9 5 6
8 1 9
2 10 2
9 8 7

3 2
 2 3
 5 1
 0 1
 5 1

#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";
  }
}
