#include <bits/stdc++.h>
using namespace std;
const int oo = 1e9;
const int maxn = 1e5 + 5;
int val[maxn * 8][5];
int _lz[maxn * 8];
int n, q;
string s;
void upd_node(int x, int v) {
  _lz[x] += v;
  val[x][0] += v;
  val[x][1] -= v;
  val[x][2] -= v;
  val[x][4] += v;
}
void merge_node(int x, int y, int z) {
  val[x][0] = max(val[y][0], val[z][0]);
  val[x][1] = max(val[y][1], val[z][1]);
  val[x][1] = max(val[x][1], val[y][0] - 2 * val[z][4]);
  val[x][2] = max(val[y][2], val[z][2]);
  val[x][2] = max(val[x][2], val[z][0] - 2 * val[y][4]);
  val[x][3] = max(val[y][3], val[z][3]);
  val[x][3] = max(val[x][3], val[y][1] + val[z][0]);
  val[x][3] = max(val[x][3], val[y][0] + val[z][2]);
  val[x][4] = min(val[y][4], val[z][4]);
}
void pushdown(int x) {
  upd_node(2 * x, _lz[x]);
  upd_node(2 * x + 1, _lz[x]);
  _lz[x] = 0;
  merge_node(x, 2 * x, 2 * x + 1);
}
void upd(int x, int L, int R, int l, int r, int v) {
  if (l > R || L > r) return;
  if (l <= L && R <= r) {
    upd_node(x, v);
    return;
  }
  if (L < R) {
    pushdown(x);
    int M = (L + R) >> 1;
    upd(2 * x, L, M, l, r, v);
    upd(2 * x + 1, M + 1, R, l, r, v);
    merge_node(x, 2 * x, 2 * x + 1);
  }
}
void build(int x, int L, int R) {
  if (L == R) {
    val[x][0] = val[x][4] = 0;
    val[x][1] = 0;
    val[x][2] = 0;
    val[x][3] = 0;
    return;
  }
  int M = (L + R) >> 1;
  build(2 * x, L, M);
  build(2 * x + 1, M + 1, R);
}
void deb(int x, int L, int R) {
  if (L == R) {
    cout << L << " " << val[x][0] << endl;
    return;
  }
  pushdown(x);
  int M = (L + R) >> 1;
  deb(2 * x, L, M);
  deb(2 * x + 1, M + 1, R);
}
int main() {
  cin >> n >> q;
  int N = 2 * (n - 1) - 1;
  cin >> s;
  build(1, 0, N);
  for (int i = (0); i < (((int)s.size())); i++) {
    int v = (s[i] == '(' ? 1 : -1);
    upd(1, 0, N, i, N, v);
  }
  cout << val[1][3] << endl;
  for (int i = (0); i < (q); i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    if (s[x] == '(') {
      upd(1, 0, N, x, N, -1);
      upd(1, 0, N, y, N, 1);
    } else {
      upd(1, 0, N, x, N, 1);
      upd(1, 0, N, y, N, -1);
    }
    if (s[y] == ')') {
      upd(1, 0, N, y, N, 1);
      upd(1, 0, N, x, N, -1);
    } else {
      upd(1, 0, N, y, N, -1);
      upd(1, 0, N, x, N, 1);
    }
    swap(s[x], s[y]);
    cout << val[1][3] << '\n';
  }
  return 0;
}
