#include <bits/stdc++.h>
using namespace std;
long long read() {
  int f = 1;
  long long res = 0;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = -f;
  } while (ch < '0' || ch > '9');
  do {
    res = res * 10 + ch - '0';
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  return f == 1 ? res : -res;
}
const int N = 200010;
const long long INF = 2000000000000LL;
int n, m, q;
int mod = 998244353;
int head[N], to[N << 1], nxt[N << 1], color[N << 1], tot;
int father[N], sz[N];
char str[N];
int A[N], B[N];
void addEdge(int u, int v, int c) {
  tot++;
  nxt[tot] = head[u];
  to[tot] = v;
  color[tot] = c;
  head[u] = tot;
}
long long myPow(long long a, int b) {
  if (b == 0) return 1;
  long long ans = myPow(a, b / 2);
  ans *= ans;
  ans %= mod;
  if (b % 2 == 1) {
    ans *= a;
    ans %= mod;
  }
  return ans;
}
void addMod(long long &a, int b) {
  a += b;
  a %= mod;
}
long long mmin(long long a, long long b) { return a < b ? a : b; }
long long mmax(long long a, long long b) { return a > b ? a : b; }
struct ST {
  int pref[N * 4], mi[N * 4], mx[N * 4], lv[N * 4], vr[N * 4], lvr[N * 4];
  void update(int x) {
    int npref = pref[x * 2 + 1] + pref[x * 2];
    int nmi = mi[x * 2 + 1] + pref[x * 2];
    int nmx = mx[x * 2 + 1] + pref[x * 2];
    int nlv = lv[x * 2 + 1] - pref[x * 2];
    int nvr = vr[x * 2 + 1] - pref[x * 2];
    int nlvr = lvr[x * 2 + 1];
    pref[x] = npref;
    mi[x] = mmin(mi[x * 2], nmi);
    mx[x] = mmax(mx[x * 2], nmx);
    lv[x] = mmax(lv[x * 2], mmax(nlv, mx[x * 2] - 2 * nmi));
    vr[x] = mmax(vr[x * 2], mmax(nvr, nmx - 2 * mi[x * 2]));
    lvr[x] =
        mmax(mmax(lvr[x * 2], nlvr), mmax(lv[x * 2] + nmx, mx[x * 2] + nvr));
  }
  void build(int x, int nl, int nr) {
    if (nl == nr) {
      if (str[nl] == '(') {
        pref[x] = 1;
        mi[x] = 0;
        mx[x] = 1;
        lv[x] = 0;
        vr[x] = 1;
        lvr[x] = 1;
      } else {
        pref[x] = -1;
        mi[x] = -1;
        mx[x] = 0;
        lv[x] = 2;
        vr[x] = 1;
        lvr[x] = 1;
      }
      return;
    }
    int m = (nl + nr) / 2;
    build(x * 2, nl, m);
    build(x * 2 + 1, m + 1, nr);
    update(x);
  }
  void set(int pos, char ch, int x, int nl, int nr) {
    if (pos < nl || pos > nr) return;
    if (nl == nr) {
      if (ch == '(') {
        pref[x] = 1;
        mi[x] = 0;
        mx[x] = 1;
        lv[x] = 0;
        vr[x] = 1;
        lvr[x] = 1;
      } else {
        pref[x] = -1;
        mi[x] = -1;
        mx[x] = 0;
        lv[x] = 2;
        vr[x] = 1;
        lvr[x] = 1;
      }
      return;
    }
    int m = (nl + nr) / 2;
    set(pos, ch, x * 2, nl, m);
    set(pos, ch, x * 2 + 1, m + 1, nr);
    update(x);
  }
} st;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> q;
  cin >> str + 1;
  st.build(1, 1, (n - 1) * 2);
  cout << st.lvr[1] << endl;
  for (int i = 0; i < q; i++) {
    int pos1, pos2;
    cin >> pos1 >> pos2;
    int ch = str[pos1];
    str[pos1] = str[pos2];
    str[pos2] = ch;
    st.set(pos1, str[pos1], 1, 1, (n - 1) * 2);
    st.set(pos2, str[pos2], 1, 1, (n - 1) * 2);
    cout << st.lvr[1] << endl;
  }
  return 0;
}
