#include <bits/stdc++.h>
using std::cerr;
using std::endl;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int MAXN = 100005;
int n, q, a[MAXN << 1];
struct info {
  int sum;
  int pmin, pmax;
  int smin, smax;
  int pres, sres, allres;
  int res;
  inline void init() {
    sum = 0;
    pmin = smin = 1e9;
    pmax = smax = pres = sres = allres = res = -1e9;
  }
  inline friend info operator+(info x, info y) {
    info ret;
    ret.init();
    ret.sum = x.sum + y.sum;
    ret.pmin = std::min(x.pmin, x.sum + y.pmin);
    ret.pmax = std::max(x.pmax, x.sum + y.pmax);
    ret.smin = std::min(y.smin, y.sum + x.smin);
    ret.smax = std::max(y.smax, y.sum + x.smax);
    ret.pres = std::max(x.pres, std::max(x.allres + y.pmax, -x.sum + y.pres));
    ret.sres = std::max(y.sres, std::max(y.allres - x.smin, y.sum + x.sres));
    ret.allres = std::max(x.allres + y.sum, y.allres - x.sum);
    ret.res = std::max(std::max(x.res, y.res),
                       std::max(x.sres + y.pmax, y.pres - x.smin));
    return ret;
  }
} b[MAXN << 3];
int loc;
void build(int o, int l, int r) {
  if (l == r) {
    b[o].sum = a[l];
    b[o].pmin = b[o].smin = std::min(a[l], 0);
    b[o].pmax = b[o].smax = std::max(a[l], 0);
    b[o].pres = b[o].sres = b[o].allres = b[o].res = 1;
    return;
  }
  build((o << 1), l, ((l + r) >> 1));
  build(((o << 1) | 1), ((l + r) >> 1) + 1, r);
  b[o] = b[(o << 1)] + b[((o << 1) | 1)];
}
void update(int o, int l, int r) {
  if (l == r) {
    b[o].sum = a[l];
    b[o].pmin = b[o].smin = std::min(a[l], 0);
    b[o].pmax = b[o].smax = std::max(a[l], 0);
    b[o].pres = b[o].sres = b[o].allres = b[o].res = 1;
    return;
  }
  if (loc <= ((l + r) >> 1))
    update((o << 1), l, ((l + r) >> 1));
  else
    update(((o << 1) | 1), ((l + r) >> 1) + 1, r);
  b[o] = b[(o << 1)] + b[((o << 1) | 1)];
}
void write(int o, int l, int r) {
  if (l == r) {
    cerr << b[o].sum << " ";
    return;
  }
  write((o << 1), l, ((l + r) >> 1));
  write(((o << 1) | 1), ((l + r) >> 1) + 1, r);
  b[o] = b[(o << 1)] + b[((o << 1) | 1)];
}
int main() {
  n = read(), q = read();
  for (int i = (1); i <= ((n - 1) << 1); ++i) {
    char ch = getchar();
    while (ch != '(' && ch != ')') ch = getchar();
    if (ch == '(')
      a[i] = 1;
    else
      a[i] = -1;
  }
  build(1, 1, (n - 1) << 1);
  printf("%d\n", b[1].res);
  while (q--) {
    int x = read(), y = read();
    std::swap(a[x], a[y]);
    loc = x;
    update(1, 1, (n - 1) << 1);
    loc = y;
    update(1, 1, (n - 1) << 1);
    printf("%d\n", b[1].res);
  }
  return 0;
}
