#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline T1 max(T1 a, T2 b) {
  return a < b ? b : a;
}
template <typename T1, typename T2>
inline T1 min(T1 a, T2 b) {
  return a < b ? a : b;
}
const char lf = '\n';
namespace ae86 {
const int bufl = 1 << 15;
char buf[bufl], *s = buf, *t = buf;
inline int fetch() {
  if (s == t) {
    t = (s = buf) + fread(buf, 1, bufl, stdin);
    if (s == t) return EOF;
  }
  return *s++;
}
inline int ty() {
  int a = 0;
  int b = 1, c = fetch();
  while (!isdigit(c)) b ^= c == '-', c = fetch();
  while (isdigit(c)) a = a * 10 + c - 48, c = fetch();
  return b ? a : -a;
}
template <typename T>
inline int ts(T *s) {
  int a = 0, c = fetch();
  while (c <= 32 && c != EOF) c = fetch();
  while (c > 32 && c != EOF) s[a++] = c, c = fetch();
  s[a] = 0;
  return a;
}
}  // namespace ae86
using ae86::ts;
using ae86::ty;
inline int dir(int x) { return x == '(' ? 1 : -1; }
const int _ = 100007 << 1;
struct sgt {
  static const int _t = _ << 2;
  int mx[_t], md[_t], mxd[_t], mdx[_t], ans[_t], tadd[_t];
  void up(int x) {
    mx[x] = max(mx[(x << 1)], mx[(x << 1 | 1)]);
    md[x] = max(md[(x << 1)], md[(x << 1 | 1)]);
    mxd[x] = max(max(mxd[(x << 1)], mxd[(x << 1 | 1)]),
                 mx[(x << 1)] + md[(x << 1 | 1)]);
    mdx[x] = max(max(mdx[(x << 1)], mdx[(x << 1 | 1)]),
                 md[(x << 1)] + mx[(x << 1 | 1)]);
    ans[x] = max(max(ans[(x << 1)], ans[(x << 1 | 1)]),
                 max(mx[(x << 1)] + mdx[(x << 1 | 1)],
                     mxd[(x << 1)] + mx[(x << 1 | 1)]));
  }
  void putadd(int x, int d) {
    tadd[x] += d;
    mx[x] += d, md[x] -= d + d;
    mdx[x] -= d, mxd[x] -= d;
  }
  void dwn(int x) {
    if (tadd[x])
      putadd((x << 1), tadd[x]), putadd((x << 1 | 1), tadd[x]), tadd[x] = 0;
  }
  void plant(int x, int l, int r, int val[]) {
    tadd[x] = 0;
    if (l == r) {
      ans[x] = 0, mx[x] = val[l], md[x] = -2 * val[l],
      mxd[x] = mdx[x] = mx[x] + md[x];
      return;
    }
    plant((x << 1), l, ((l + r) >> 1), val),
        plant((x << 1 | 1), ((l + r) >> 1) + 1, r, val), up(x);
  }
  void change(int x, int l, int r, int tl, int tr, int dlt) {
    if (tl <= l && r <= tr) {
      putadd(x, dlt);
      return;
    }
    dwn(x);
    if (tl <= ((l + r) >> 1)) change((x << 1), l, ((l + r) >> 1), tl, tr, dlt);
    if (tr > ((l + r) >> 1))
      change((x << 1 | 1), ((l + r) >> 1) + 1, r, tl, tr, dlt);
    up(x);
  }
} t;
int n, nn, qn, str[_] = {0}, dep[_] = {0};
int main() {
  ios::sync_with_stdio(0), cout.tie(nullptr);
  n = ty(), qn = ty(), nn = ts(str + 1);
  for (int i = 1; i <= nn; i++) str[i] = dir(str[i]);
  for (int i = 1; i <= nn; i++) dep[i] = dep[i - 1] + str[i];
  t.plant(1, 1, nn, dep), cout << t.ans[1] << lf;
  for (int qq = 1; qq <= qn; qq++) {
    int l = ty(), r = ty();
    if (l > r) swap(l, r);
    if (str[l] != str[r]) {
      t.change(1, 1, nn, l, r - 1, -2 * str[l]);
      swap(str[l], str[r]);
    }
    cout << t.ans[1] << lf;
  }
  return 0;
}
