#include <bits/stdc++.h>
using namespace std;
namespace fastIO {
bool IOerror = 0;
inline char nc() {
  static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000;
  if (p1 == pend) {
    p1 = buf;
    pend = buf + fread(buf, 1, 100000, stdin);
    if (pend == p1) {
      IOerror = 1;
      return -1;
    }
  }
  return *p1++;
}
inline bool blank(char ch) {
  return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
}
inline long long read() {
  bool sign = 0;
  char ch = nc();
  long long x = 0;
  for (; blank(ch); ch = nc())
    ;
  if (IOerror) return 0;
  if (ch == '-') sign = 1, ch = nc();
  for (; ch >= '0' && ch <= '9'; ch = nc()) x = x * 10 + ch - '0';
  if (sign) x = -x;
  return x;
}
};  // namespace fastIO
using namespace fastIO;
long long a[1000010], c[1000010], sum[1000010], lmx[1000010], rmn[1000010],
    mx1[1000010], lc[1000010], rc[1000010];
void pushup(long long x, long long l, long long r) {
  long long mid = (l + r) / 2;
  sum[x] = sum[x << 1] + sum[x << 1 | 1];
  lmx[x] = max(lmx[x << 1], sum[x << 1] + lmx[x << 1 | 1]);
  rmn[x] = min(rmn[x << 1 | 1], sum[x << 1 | 1] + rmn[x << 1]);
  mx1[x] = max(mx1[x << 1] + sum[x << 1 | 1], mx1[x << 1 | 1] - sum[x << 1]);
  lc[x] = max(max(lc[x << 1], mx1[x << 1] + lmx[x << 1 | 1]),
              lc[x << 1 | 1] - sum[x << 1]);
  rc[x] = max(max(rc[x << 1 | 1], mx1[x << 1 | 1] - rmn[x << 1]),
              rc[x << 1] + sum[x << 1 | 1]);
  c[x] = max(max(c[x << 1], c[x << 1 | 1]),
             max(lc[x << 1 | 1] - rmn[x << 1], rc[x << 1] + lmx[x << 1 | 1]));
}
void build(long long l, long long r, long long x) {
  if (l == r) {
    sum[x] = a[l];
    lmx[x] = max(a[l], 0ll);
    rmn[x] = min(a[l], 0ll);
    mx1[x] = 1;
    lc[x] = 1;
    rc[x] = 1;
    c[x] = 1;
    return;
  }
  long long mid = (l + r) / 2;
  build(l, mid, x << 1);
  build(mid + 1, r, x << 1 | 1);
  pushup(x, l, r);
}
void modify(long long l, long long r, long long p, long long v, long long x) {
  if (l == r) {
    sum[x] = v;
    lmx[x] = max(v, 0ll);
    rmn[x] = min(v, 0ll);
    mx1[x] = 1;
    lc[x] = 1;
    rc[x] = 1;
    c[x] = 1;
    return;
  }
  long long mid = (l + r) / 2;
  if (p <= mid)
    modify(l, mid, p, v, x << 1);
  else
    modify(mid + 1, r, p, v, x << 1 | 1);
  pushup(x, l, r);
}
signed main() {
  long long n = read(), q = read();
  for (long long i = 1; i <= 2 * (n - 1); i++) {
    char ch = nc();
    if (ch == '(')
      a[i] = 1;
    else
      a[i] = -1;
  }
  build(1, 2 * (n - 1), 1);
  cout << c[1] << '\n';
  for (long long i = 1; i <= q; i++) {
    long long l = read(), r = read();
    modify(1, 2 * (n - 1), l, a[r], 1);
    modify(1, 2 * (n - 1), r, a[l], 1);
    swap(a[l], a[r]);
    cout << c[1] << '\n';
  }
  return 0;
}
