#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
using namespace std;
const long long nmax = 100005;
const long long inf = 1e18;
long long n, q;
string s;
struct tree {
  long long last, max_abc, max_a, max_bc, max_ab, max_b;
} aint[8 * nmax];
tree merge(tree a, tree b) {
  tree ANS;
  ANS.last = (a.last + b.last);
  ANS.max_abc = max({a.max_abc, a.max_ab + b.max_a + a.last,
                     a.max_a + b.max_bc - a.last, b.max_abc});
  ANS.max_a = max({a.max_a, b.max_a + a.last});
  ANS.max_bc = max({a.max_bc, a.max_b + b.max_a + a.last, b.max_bc - a.last});
  ANS.max_ab =
      max({a.max_ab, a.max_a + b.max_b - 2 * a.last, b.max_ab - a.last});
  ANS.max_b = max({a.max_b, b.max_b - 2 * a.last});
  return ANS;
}
void update(long long l, long long r, long long pos, long long nod) {
  if (l == r) {
    if (s[pos - 1] == '(') aint[nod] = {1, 1, 1, 1, 0, 0};
    if (s[pos - 1] == ')') aint[nod] = {-1, 1, 0, 1, 1, 2};
  } else {
    long long mid = l + (r - l) / 2;
    if (pos <= mid)
      update(l, mid, pos, 2 * nod);
    else
      update(mid + 1, r, pos, 2 * nod + 1);
    aint[nod] = merge(aint[2 * nod], aint[2 * nod + 1]);
  }
}
void debug(long long l, long long r, long long nod) {
  cout << l << ' ' << r << "    ";
  cout << aint[nod].last << ' ' << aint[nod].max_abc << ' ' << aint[nod].max_a
       << ' ' << aint[nod].max_bc << ' ' << aint[nod].max_ab << ' '
       << aint[nod].max_b << '\n';
  if (l != r) {
    long long mid = l + (r - l) / 2;
    debug(l, mid, 2 * nod);
    debug(mid + 1, r, 2 * nod + 1);
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cerr.tie(0);
  cout.tie(0);
  srand(chrono::steady_clock::now().time_since_epoch().count());
  cin >> n >> q >> s;
  for (long long i = 0; i < s.size(); i++) {
    update(1, 2 * n - 2, i + 1, 1);
  }
  cout << aint[1].max_abc << '\n';
  for (long long i = 1; i <= q; i++) {
    long long l, r;
    cin >> l >> r;
    swap(s[l - 1], s[r - 1]);
    update(1, 2 * n - 2, l, 1);
    update(1, 2 * n - 2, r, 1);
    cout << aint[1].max_abc << '\n';
  }
}
