#include <bits/stdc++.h>
template <typename T>
inline void ckmax(T& x, T y) {
  x = (y > x ? y : x);
}
template <typename T>
inline void ckmin(T& x, T y) {
  x = (y < x ? y : x);
}
using namespace std;
const long long mod = 1e9 + 7;
const long double eps = 1e-8;
inline long long fpow(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return res;
}
long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 3) + (x << 1) + (c ^ 48);
    c = getchar();
  }
  return x * f;
}
const long long N = 2e5 + 10;
long long n, q;
char s[N];
long long cnt;
struct segmentree {
  long long sufral[N << 2], sufrcl[N << 2], preral[N << 2], prercl[N << 2],
      secl[N << 2], secr[N << 2], val[N << 2];
  void print() {
    printf("\n-----------cnt:%lld\n", ++cnt);
    puts("-----------------------------12-----------------");
    puts("");
    for (long long i = (1), iE = (10); i <= iE; i++)
      printf("%lld %lld %lld %lld %lld %lld %lld\n", sufral[i], sufrcl[i],
             prercl[i], preral[i], secl[i], secr[i], val[i]);
    puts("-----------------------------23------------------");
    puts("");
  }
  void push_up(long long x) {
    if (secl[x << 1] > secr[x << 1 | 1])
      secl[x] = secl[x << 1] - secr[x << 1 | 1] + secl[x << 1 | 1],
      secr[x] = secr[x << 1];
    else
      secr[x] = secr[x << 1 | 1] - secl[x << 1] + secr[x << 1],
      secl[x] = secl[x << 1 | 1];
    sufral[x] = max(sufral[x << 1 | 1],
                    max(sufral[x << 1] + secl[x << 1 | 1] - secr[x << 1 | 1],
                        sufrcl[x << 1] + secr[x << 1 | 1] + secl[x << 1 | 1]));
    sufrcl[x] = max(sufrcl[x << 1 | 1],
                    sufrcl[x << 1] + secr[x << 1 | 1] - secl[x << 1 | 1]);
    prercl[x] =
        max(prercl[x << 1], secl[x << 1] - secr[x << 1] + prercl[x << 1 | 1]);
    preral[x] = max(preral[x << 1],
                    max(secl[x << 1] + secr[x << 1] + prercl[x << 1 | 1],
                        secr[x << 1] - secl[x << 1] + preral[x << 1 | 1]));
    val[x] = max(max(sufral[x << 1] + prercl[x << 1 | 1],
                     sufrcl[x << 1] + preral[x << 1 | 1]),
                 max(val[x << 1], val[x << 1 | 1]));
  }
  void build(long long l, long long r, long long x) {
    if (l == r) {
      long long k = (s[l] == '(') ? 1 : -1;
      sufral[x] = preral[x] = 1;
      sufrcl[x] = max(-k, 0ll);
      prercl[x] = max(k, 0ll);
      secl[x] = (k == 1), secr[x] = (k == -1);
      val[x] = 1;
      return;
    }
    long long mid = (l + r) >> 1;
    build(l, mid, x << 1);
    build(mid + 1, r, x << 1 | 1);
    push_up(x);
  }
  void modify(long long pos, long long l, long long r, long long x,
              long long k) {
    if (l == r) {
      sufral[x] = preral[x] = 1;
      sufrcl[x] = max(-k, 0ll);
      prercl[x] = max(k, 0ll);
      secl[x] = (k == 1), secr[x] = (k == -1);
      val[x] = 1;
      return;
    }
    long long mid = (l + r) >> 1;
    if (pos <= mid)
      modify(pos, l, mid, x << 1, k);
    else
      modify(pos, mid + 1, r, x << 1 | 1, k);
    push_up(x);
  }
} st;
signed main() {
  n = read(), q = read();
  scanf("%s", s + 1);
  n = strlen(s + 1);
  st.build(1, n, 1);
  printf("%lld\n", st.val[1]);
  while (q--) {
    long long x = read(), y = read();
    st.modify(x, 1, n, 1, s[y] == '(' ? 1 : -1);
    st.modify(y, 1, n, 1, s[x] == '(' ? 1 : -1);
    swap(s[x], s[y]);
    printf("%lld\n", st.val[1]);
  }
}
