#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
int n, q, a[MAXN];
long long int seg[MAXN * 4], lazy[MAXN * 4], ii[MAXN * 4], jj[MAXN * 4],
    ij[MAXN * 4], jk[MAXN * 4];
string s;
inline void down(int ind) {
  long long int val = lazy[ind];
  ii[ind * 2] += val;
  ii[ind * 2 + 1] += val;
  jj[ind * 2] -= 2ll * val;
  jj[ind * 2 + 1] -= 2ll * val;
  ij[ind * 2] -= val;
  ij[ind * 2 + 1] -= val;
  jk[ind * 2] -= val;
  jk[ind * 2 + 1] -= val;
  lazy[ind * 2] += val;
  lazy[ind * 2 + 1] += val;
  lazy[ind] = 0;
  return;
}
inline void up(int ind) {
  seg[ind] = max(seg[ind * 2], seg[ind * 2 + 1]);
  seg[ind] = max(seg[ind], max(ij[ind * 2] + ii[ind * 2 + 1],
                               ii[ind * 2] + jk[ind * 2 + 1]));
  ii[ind] = max(ii[ind * 2], ii[ind * 2 + 1]);
  jj[ind] = max(jj[ind * 2], jj[ind * 2 + 1]);
  ij[ind] =
      max(max(ij[ind * 2], ij[ind * 2 + 1]), ii[ind * 2] + jj[ind * 2 + 1]);
  jk[ind] =
      max(max(jk[ind * 2], jk[ind * 2 + 1]), jj[ind * 2] + ii[ind * 2 + 1]);
  return;
}
void add(long long int val, int l, int r, int b = 0, int e = n, int ind = 1) {
  if (r <= b || e <= l) return;
  if (l <= b && r >= e) {
    lazy[ind] += val;
    ii[ind] += val;
    jj[ind] -= 2ll * val;
    ij[ind] -= val;
    jk[ind] -= val;
    return;
  }
  down(ind);
  int mid = (b + e) / 2;
  add(val, l, r, b, mid, ind * 2);
  add(val, l, r, mid, e, ind * 2 + 1);
  up(ind);
  return;
}
void build(int b = 0, int e = n, int ind = 1) {
  if (b + 1 == e) {
    seg[ind] = 0ll;
    ii[ind] = a[b];
    ij[ind] = jk[ind] = -a[b];
    jj[ind] = -2ll * a[b];
    return;
  }
  int mid = (b + e) / 2;
  build(b, mid, ind * 2);
  build(mid, e, ind * 2 + 1);
  up(ind);
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> q >> s;
  n = 2 * n - 1;
  for (int i = 1; i < n; i++)
    a[i] = a[i - 1] + (s[i - 1] == '(') - (s[i - 1] == ')');
  build();
  cout << seg[1] << '\n';
  while (q--) {
    int u, v;
    cin >> u >> v;
    if (v < u) swap(u, v);
    long long int val = ((s[u - 1] == '(') ? -2ll : 2ll);
    swap(s[u - 1], s[v - 1]);
    add(val, u, v);
    cout << seg[1] << '\n';
  }
  return 0;
}
