#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0;
  bool f = 1;
  char s = getchar();
  while ((s < '0' || s > '9') && s > 0) {
    if (s == '-') f ^= 1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') x = (x << 1) + (x << 3) + s - '0', s = getchar();
  return f ? x : -x;
}
int n, m, R;
struct itn {
  int ab, a_b, dc, d_c, s, e, f;
} t[200005 << 2];
char s[200005];
inline void docnt(int x) {
  t[x].ab = max(t[x << 1 | 1].ab,
                max(t[x << 1].ab - t[x << 1 | 1].e + t[x << 1 | 1].f,
                    t[x << 1].a_b + t[x << 1 | 1].e + t[x << 1 | 1].f));
  t[x].a_b =
      max(t[x << 1 | 1].a_b, t[x << 1].a_b + t[x << 1 | 1].e - t[x << 1 | 1].f);
  t[x].dc =
      max(t[x << 1].dc, max(t[x << 1 | 1].dc - t[x << 1].f + t[x << 1].e,
                            t[x << 1 | 1].d_c + t[x << 1].f + t[x << 1].e));
  t[x].d_c = max(t[x << 1].d_c, t[x << 1 | 1].d_c + t[x << 1].f - t[x << 1].e);
  t[x].s =
      max(t[x << 1].ab + t[x << 1 | 1].d_c, t[x << 1].a_b + t[x << 1 | 1].dc);
  t[x].s = max(t[x].s, max(t[x << 1].s, t[x << 1 | 1].s));
  t[x].e = t[x << 1].e + max(0, t[x << 1 | 1].e - t[x << 1].f);
  t[x].f = t[x << 1 | 1].f + max(0, t[x << 1].f - t[x << 1 | 1].e);
}
inline void build(int x, int l, int r) {
  if (l == r) {
    if (s[l] == '(')
      t[x].ab = t[x].dc = 1, t[x].a_b = 0, t[x].d_c = 1, t[x].e = 0, t[x].f = 1;
    else
      t[x].ab = t[x].dc = 1, t[x].a_b = 1, t[x].d_c = 0, t[x].e = 1, t[x].f = 0;
    t[x].s = 1;
    return;
  }
  int mid = (l + r) >> 1;
  build(x << 1, l, mid), build(x << 1 | 1, mid + 1, r);
  docnt(x);
}
inline void change(int x, int l, int r, int z) {
  if (l == r) {
    if (s[l] == '(')
      t[x].ab = t[x].dc = 1, t[x].a_b = 0, t[x].d_c = 1, t[x].e = 0, t[x].f = 1;
    else
      t[x].ab = t[x].dc = 1, t[x].a_b = 1, t[x].d_c = 0, t[x].e = 1, t[x].f = 0;
    t[x].s = 1;
    return;
  }
  int mid = (l + r) >> 1;
  if (z <= mid)
    change(x << 1, l, mid, z);
  else
    change(x << 1 | 1, mid + 1, r, z);
  docnt(x);
}
int main() {
  n = read(), m = read(), R = (n - 1) << 1;
  scanf("%s", s + 1);
  build(1, 1, R);
  printf("%d\n", t[1].s);
  for (int i = 1; i <= m; i++) {
    int u = read(), v = read();
    swap(s[u], s[v]), change(1, 1, R, u), change(1, 1, R, v);
    printf("%d\n", t[1].s);
  }
  return 0;
}
