#include <bits/stdc++.h>
using namespace std;
const int N = 2 * 1e5 + 100;
int n, m;
char s[N];
struct node {
  int sum, lmax, lmin, rmax, rmin, ans;
  int lans, rans;
} sh[N * 4];
inline int max(int a, int b) { return ((a > b) ? a : b); }
inline int min(int a, int b) { return ((a < b) ? a : b); }
inline int get(char s) { return ((s == '(') ? -1 : 1); }
inline void pushup(int x) {
  sh[x].sum = sh[x + x].sum + sh[x + x + 1].sum;
  sh[x].ans = max(sh[x + x].ans, sh[x + x + 1].ans);
  sh[x].ans = max(sh[x].ans, sh[x + x].rans - sh[x + x + 1].lmin);
  sh[x].ans = max(sh[x].ans, sh[x + x + 1].lans + sh[x + x].rmax);
  sh[x].ans = max(sh[x].ans, sh[x + x].rmax + sh[x + x + 1].lmax);
  sh[x].ans = max(sh[x].ans, -(sh[x + x].rmin + sh[x + x + 1].lmin));
  sh[x].lmax = max(sh[x + x].lmax, sh[x + x].sum + sh[x + x + 1].lmax);
  sh[x].lmin = min(sh[x + x].lmin, sh[x + x].sum + sh[x + x + 1].lmin);
  sh[x].rmax = max(sh[x + x + 1].rmax, sh[x + x + 1].sum + sh[x + x].rmax);
  sh[x].rmin = min(sh[x + x + 1].rmin, sh[x + x + 1].sum + sh[x + x].rmin);
  sh[x].lmax = max(sh[x].lmax, 0), sh[x].rmax = max(sh[x].rmax, 0);
  sh[x].lmin = min(sh[x].lmin, 0), sh[x].rmin = min(sh[x].rmin, 0);
  sh[x].lans = max(sh[x + x].lans, sh[x + x].sum + sh[x + x + 1].lans);
  sh[x].rans = max(sh[x + x + 1].rans, -sh[x + x + 1].sum + sh[x + x].rans);
  sh[x].lans =
      max(sh[x].lans, sh[x + x].lmax - (sh[x + x].sum - sh[x + x].lmax) -
                          sh[x + x + 1].lmin);
  sh[x].rans = max(sh[x].rans,
                   sh[x + x].rmax + (sh[x + x + 1].lmax -
                                     (sh[x + x + 1].sum - sh[x + x + 1].lmax)));
}
void build(int x, int l, int r) {
  if (l == r) {
    sh[x].sum = sh[x].lmin = sh[x].lmax = sh[x].rmin = sh[x].rmax = get(s[l]);
    sh[x].lmax = max(sh[x].lmax, 0), sh[x].rmax = max(sh[x].rmax, 0);
    sh[x].lmin = min(sh[x].lmin, 0), sh[x].rmin = min(sh[x].rmin, 0);
    sh[x].ans = sh[x].lans = sh[x].rans = 1;
    return;
  }
  int mid = (l + r) >> 1;
  build(x + x, l, mid);
  build(x + x + 1, mid + 1, r);
  pushup(x);
}
void change(int x, int l, int r, int wh, int v) {
  if (l == r) {
    sh[x].sum = sh[x].lmin = sh[x].lmax = sh[x].rmin = sh[x].rmax = v;
    sh[x].lmax = max(sh[x].lmax, 0), sh[x].rmax = max(sh[x].rmax, 0);
    sh[x].lmin = min(sh[x].lmin, 0), sh[x].rmin = min(sh[x].rmin, 0);
    sh[x].ans = sh[x].lans = sh[x].rans = 1;
    return;
  }
  int mid = (l + r) >> 1;
  if (wh <= mid)
    change(x + x, l, mid, wh, v);
  else
    change(x + x + 1, mid + 1, r, wh, v);
  pushup(x);
}
signed main() {
  scanf("%d%d%s", &n, &m, s + 1);
  n = 2 * (n - 1);
  build(1, 1, n);
  printf("%d\n", sh[1].ans);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    change(1, 1, n, x, get(s[y]));
    change(1, 1, n, y, get(s[x]));
    swap(s[x], s[y]);
    printf("%d\n", sh[1].ans);
  }
}
