#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
struct node {
  int dep, diamater, deplca, depa, atolca, btolca;
  node() {}
  node(int dep, int diamater, int deplca, int depa, int atolca, int btolca)
      : dep(dep),
        diamater(diamater),
        deplca(deplca),
        depa(depa),
        atolca(atolca),
        btolca(btolca) {}
  node operator+(const node& oth) {
    node res;
    res.dep = dep + oth.dep;
    res.deplca = min(deplca, dep + oth.deplca);
    res.depa = max(depa, dep + oth.depa);
    res.atolca =
        max({atolca, oth.atolca - dep, -2 * dep - 2 * oth.deplca + depa});
    res.btolca = max({btolca, oth.btolca - dep, -2 * deplca + oth.depa + dep});
    res.diamater = max({diamater, oth.diamater, depa + oth.btolca - dep,
                        atolca + oth.depa + dep});
    return res;
  }
} tr[4 * maxn];
int N, Q;
void upd(int pos, int v, int id = 1, int l = 1, int r = N) {
  if (l == r) {
    if (v == 1) {
      tr[id] = node(1, 1, 0, 1, 0, 1);
    } else {
      tr[id] = node(-1, 1, -1, 0, 2, 1);
    }
    return;
  }
  int mid = (l + r) / 2;
  if (pos <= mid)
    upd(pos, v, id << 1, l, mid);
  else
    upd(pos, v, id << 1 | 1, mid + 1, r);
  tr[id] = tr[id << 1] + tr[id << 1 | 1];
}
int type(char x) {
  if (x == '(') return 1;
  return -1;
}
signed main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> N >> Q;
  string str;
  cin >> str;
  N = str.size();
  str = " " + str;
  for (int i = 1; i <= N; ++i) {
    upd(i, type(str[i]));
  }
  cout << tr[1].diamater << '\n';
  while (Q--) {
    int l, r;
    cin >> l >> r;
    swap(str[l], str[r]);
    upd(l, type(str[l]));
    upd(r, type(str[r]));
    cout << tr[1].diamater << '\n';
  }
}
