#include <bits/stdc++.h>
using namespace std;
int const N = 200000;
char s[N];
int z[N << 2], n, q;
struct S {
  int mx[3][3];
  S() {
    for (int i = 0; i < (int)(3); ++i)
      for (int j = i; j < (int)(3); ++j) mx[i][j] = 0;
  }
  int *operator[](int i) { return mx[i]; }
  int const *operator[](int i) const { return mx[i]; }
  S operator+(S const &o) const {
    S an;
    for (int i = 0; i < (int)(3); ++i)
      for (int j = i; j < (int)(3); ++j) an[i][j] = mx[i][j];
    for (int i = 0; i < (int)(3); ++i)
      for (int j = i; j < (int)(3); ++j) an[i][j] = max(an[i][j], o[i][j]);
    for (int i = 0; i < (int)(3); ++i)
      for (int j = i + 1; j < (int)(3); ++j)
        for (int k = i; k < (int)(j); ++k)
          an[i][j] = max(an[i][j], mx[i][k] + o[k + 1][j]);
    return an;
  }
  void up(int v) {
    for (int i = 0; i < (int)(3); ++i)
      for (int j = i; j < (int)(3); ++j)
        for (int k = i; k < (int)(j + 1); ++k) {
          if (k == 1)
            mx[i][j] -= v << 1;
          else
            mx[i][j] += v;
        }
  }
} sg[N << 2];
inline void up(int id, int v) {
  sg[id].up(v);
  z[id] += v;
}
inline void sl(int id, int a, int b) {
  if (!z[id]) return;
  up(a, z[id]);
  up(b, z[id]);
  z[id] = 0;
}
void ad(int x, int y, int v, int l = 1, int r = n, int id = 1) {
  if (l > y || r < x) return;
  if (l >= x && r <= y) return up(id, v);
  int m = l + r >> 1, a = id << 1, b = a | 1;
  sl(id, a, b);
  ad(x, y, v, l, m, a);
  ad(x, y, v, m + 1, r, b);
  sg[id] = sg[a] + sg[b];
}
int main() {
  scanf("%d%d%s", &n, &q, s + 1);
  n = n - 1 << 1;
  for (int i = 1; i < (int)(n + 1); ++i) ad(i, n, s[i] == '(' ? 1 : -1);
  printf("%d\n", sg[1][0][2]);
  while (q--) {
    int a, b;
    scanf("%d%d", &a, &b);
    if (a > b) swap(a, b);
    ad(a, b - 1, s[a] == '(' ? -2 : 2);
    swap(s[a], s[b]);
    printf("%d\n", sg[1][0][2]);
  }
}
