#include <bits/stdc++.h>
const double esp = 1e-6;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int inf = 1e9;
using namespace std;
int read() {
  char ch = getchar();
  int x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int N = 2e5 + 10;
int n, q;
string s;
struct node {
  int height, amx, bmin, lmax, rmax, ans;
  node(int height = 0, int amx = 0, int bmin = 0, int lmax = 0, int rmax = 0,
       int ans = 0)
      : height(height),
        amx(amx),
        bmin(bmin),
        lmax(lmax),
        rmax(rmax),
        ans(ans) {}
  node operator+(const node& a) const {
    node temp;
    temp.height = height + a.height;
    temp.amx = max(amx, a.amx + height);
    temp.bmin = min(bmin, a.bmin + height);
    temp.lmax = max(max(lmax, a.lmax - height), amx - 2 * (a.bmin + height));
    temp.rmax = max(max(rmax, a.rmax - height), a.amx - 2 * bmin + height);
    temp.ans =
        max(max(ans, a.ans), max(lmax + a.amx + height, a.rmax + amx - height));
    return temp;
  }
} tree[4 * N];
void build(int l, int r, int num) {
  if (l == r) {
    int k = s[l - 1] == '(' ? 1 : -1;
    tree[num].height = k;
    tree[num].amx = tree[num].bmin = k;
    tree[num].lmax = tree[num].rmax = -k;
    tree[num].ans = 0;
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, num << 1);
  build(mid + 1, r, num << 1 | 1);
  tree[num] = tree[num << 1] + tree[num << 1 | 1];
}
void build2(int l, int r, int k, int x) {
  if (l == r) {
    build(l, r, k);
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid)
    build2(l, mid, k << 1, x);
  else
    build2(mid + 1, r, k << 1 | 1, x);
  tree[k] = tree[k << 1] + tree[k << 1 | 1];
}
void print(int l, int r, int k) {
  if (l == r) {
    cout << tree[k].ans << endl;
    return;
  }
  int mid = (l + r) >> 1;
  print(l, mid, k << 1);
  print(mid + 1, r, k << 1 | 1);
}
int main() {
  n = read();
  q = read();
  cin >> s;
  n = 2 * (n - 1);
  build(1, n, 1);
  cout << tree[1].ans << endl;
  int x, y;
  while (q--) {
    x = read();
    y = read();
    x--, y--;
    swap(s[x], s[y]);
    build2(1, n, 1, x + 1);
    build2(1, n, 1, y + 1);
    cout << tree[1].ans << endl;
  }
  return 0;
}
