#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmin(T &x, T y) {
  return x > y ? x = y, 1 : 0;
}
template <typename T>
inline bool chkmax(T &x, T y) {
  return x < y ? x = y, 1 : 0;
}
template <typename T>
inline void read(T &x) {
  char ch = getchar();
  int f = 1;
  x = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  x *= f;
}
template <typename T, typename... Args>
inline void read(T &x, Args &...args) {
  read(x), read(args...);
}
int n, m, tag[200050 << 2], d[200050];
char s[200050];
struct node {
  int mx, mn, _xy, _yz, ans;
  void init(int w) { ans = 0, mx = mn = w, _xy = _yz = -w; }
  node operator+(const node &x) const {
    node r;
    r.mx = max(mx, x.mx), r.mn = min(mn, x.mn);
    r.ans = max(ans, x.ans), chkmax(r.ans, max(mx + x._yz, _xy + x.mx));
    r._xy = max(_xy, x._xy), chkmax(r._xy, mx - 2 * x.mn);
    r._yz = max(_yz, x._yz), chkmax(r._yz, x.mx - 2 * mn);
    return r;
  }
} t[200050 << 2];
void put_tag(int u, int w) {
  t[u].mx += w, t[u].mn += w, t[u]._xy -= w, t[u]._yz -= w;
  tag[u] += w;
}
void push(int u) {
  if (tag[u]) put_tag(u << 1, tag[u]), put_tag(u << 1 | 1, tag[u]), tag[u] = 0;
}
void build(int u, int l, int r) {
  if (l == r) return t[u].init(d[l]);
  build(u << 1, l, ((l + r) >> 1)), build(u << 1 | 1, ((l + r) >> 1) + 1, r);
  t[u] = t[u << 1] + t[u << 1 | 1];
}
void modify(int u, int l, int r, int tl, int tr, int w) {
  if (tl <= l && r <= tr) return put_tag(u, w);
  push(u);
  if (tl <= ((l + r) >> 1)) modify(u << 1, l, ((l + r) >> 1), tl, tr, w);
  if (((l + r) >> 1) < tr) modify(u << 1 | 1, ((l + r) >> 1) + 1, r, tl, tr, w);
  t[u] = t[u << 1] + t[u << 1 | 1];
}
int main() {
  read(n), (--n) *= 2, read(m);
  scanf("%s", s + 1);
  for (register int i = 1; i <= n; ++i)
    d[i] = d[i - 1] + (s[i] == '(' ? 1 : -1);
  build(1, 1, n);
  printf("%d\n", t[1].ans);
  int x, y;
  while (m--) {
    read(x, y);
    if (s[x] != s[y]) {
      int val = s[x] == '(' ? -2 : 2;
      modify(1, 1, n, x, n, val);
      modify(1, 1, n, y, n, -val);
      swap(s[x], s[y]);
    }
    printf("%d\n", t[1].ans);
  }
  return 0;
}
