#include <bits/stdc++.h>
using namespace std;
int max_v[4000000], max_l[4000000], max_r[4000000], max_ans[4000000];
int min_v[4000000];
int add_v[4000000];
int a[4000000];
string s;
int n, q;
void update(int t, int v) {
  add_v[t] += v;
  max_v[t] += v;
  min_v[t] += v;
  max_l[t] -= v;
  max_r[t] -= v;
}
void push_down(int t, int l, int r) {
  if (add_v[t] == 0) return;
  update(t << 1, add_v[t]);
  update(t << 1 | 1, add_v[t]);
  add_v[t] = 0;
}
void print(int t, int l, int r) {
  printf(
      "t = %d l = %d r = %d max_ans = %d max_v = %d min_v = %d  max_l = %d "
      "max_r = %d\n",
      t, l, r, max_ans[t], max_v[t], min_v[t], max_l[t], max_r[t]);
}
void push_up(int t, int l, int r) {
  int t1 = max(max_ans[t << 1], max_ans[t << 1 | 1]);
  int t2 = max_r[t << 1] + max_v[t << 1 | 1];
  int t3 = max_v[t << 1] + max_l[t << 1 | 1];
  max_ans[t] = max(t1, max(t2, t3));
  max_v[t] = max(max_v[t << 1], max_v[t << 1 | 1]);
  min_v[t] = min(min_v[t << 1], min_v[t << 1 | 1]);
  max_l[t] = max(max(max_l[t << 1], max_l[t << 1 | 1]),
                 max_v[t << 1 | 1] - 2 * min_v[t << 1]);
  max_r[t] = max(max(max_r[t << 1], max_r[t << 1 | 1]),
                 max_v[t << 1] - 2 * min_v[t << 1 | 1]);
}
void build(int t, int l, int r) {
  add_v[t] = 0;
  if (l >= r) {
    max_v[t] = a[l];
    min_v[t] = a[l];
    max_l[t] = max_r[t] = a[l] - 2 * a[l];
    max_ans[t] = 0;
    return;
  }
  push_down(t, l, r);
  int mid = (l + r) >> 1;
  build(t << 1, l, mid);
  build(t << 1 | 1, mid + 1, r);
  push_up(t, l, r);
}
void update(int t, int l, int r, int ql, int qr) {
  if (l > r) return;
  push_down(t, l, r);
  if (ql <= l && qr >= r) {
    if (s[ql] == '(')
      update(t, 2);
    else
      update(t, -2);
    return;
  }
  int mid = (l + r) >> 1;
  if (ql <= mid) update(t << 1, l, mid, ql, qr);
  if (qr > mid) update(t << 1 | 1, mid + 1, r, ql, qr);
  push_up(t, l, r);
}
int main() {
  cin >> n >> q;
  n = 2 * (n - 1);
  cin >> s;
  int t = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] == '(')
      t++;
    else
      t--;
    a[i] = t;
  }
  build(1, 0, n - 1);
  printf("%d\n", max_ans[1]);
  for (int i = 0; i < q; ++i) {
    int l, r;
    cin >> l >> r;
    if (l > r) swap(l, r);
    l--;
    r--;
    swap(s[l], s[r]);
    update(1, 0, n - 1, l, r - 1);
    printf("%d\n", max_ans[1]);
  }
}
