#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int n, q;
char s[maxn];
struct Tree {
  int d, mx1, mx2, mx3, mx4, mx5;
} tree[maxn * 4];
void updown(int rt) {
  tree[rt].d = tree[rt << 1].d + tree[rt << 1 | 1].d;
  tree[rt].mx1 =
      max(tree[rt << 1].mx1, tree[rt << 1].d + tree[rt << 1 | 1].mx1);
  tree[rt].mx2 =
      max(tree[rt << 1].mx2, -2 * tree[rt << 1].d + tree[rt << 1 | 1].mx2);
  tree[rt].mx3 =
      max(max(tree[rt << 1].mx3, -tree[rt << 1].d + tree[rt << 1 | 1].mx3),
          tree[rt << 1].mx1 - 2 * tree[rt << 1].d + tree[rt << 1 | 1].mx2);
  tree[rt].mx4 =
      max(max(tree[rt << 1].mx4, -tree[rt << 1].d + tree[rt << 1 | 1].mx4),
          tree[rt << 1].mx2 + tree[rt << 1].d + tree[rt << 1 | 1].mx1);
  tree[rt].mx5 =
      max(max(tree[rt << 1].mx5, tree[rt << 1 | 1].mx5),
          max(tree[rt << 1].mx1 - tree[rt << 1].d + tree[rt << 1 | 1].mx4,
              tree[rt << 1].mx3 + tree[rt << 1].d + tree[rt << 1 | 1].mx1));
}
void build(int rt, int l, int r) {
  if (l == r) {
    if (s[l] == '(') {
      tree[rt].d = 1;
      tree[rt].mx1 = 1;
      tree[rt].mx2 = 0;
      tree[rt].mx3 = 0;
      tree[rt].mx4 = 1;
      tree[rt].mx5 = 1;
    } else {
      tree[rt].d = -1;
      tree[rt].mx1 = 0;
      tree[rt].mx2 = 2;
      tree[rt].mx3 = 2;
      tree[rt].mx4 = 1;
      tree[rt].mx5 = 1;
    }
    return;
  }
  int mid = (l + r) >> 1;
  build(rt << 1, l, mid);
  build(rt << 1 | 1, mid + 1, r);
  updown(rt);
}
void update(int rt, int l, int r, int x) {
  if (l == r) {
    if (s[x] == '(')
      s[x] = ')';
    else
      s[x] = '(';
    if (s[x] == '(') {
      tree[rt].d = 1;
      tree[rt].mx1 = 1;
      tree[rt].mx2 = 0;
      tree[rt].mx3 = 0;
      tree[rt].mx4 = 1;
      tree[rt].mx5 = 1;
    } else {
      tree[rt].d = -1;
      tree[rt].mx1 = 0;
      tree[rt].mx2 = 2;
      tree[rt].mx3 = 2;
      tree[rt].mx4 = 1;
      tree[rt].mx5 = 1;
    }
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid)
    update(rt << 1, l, mid, x);
  else
    update(rt << 1 | 1, mid + 1, r, x);
  updown(rt);
}
int main() {
  scanf("%d%d%s", &n, &q, s + 1);
  build(1, 1, 2 * (n - 1));
  cout << tree[1].mx5 << endl;
  for (int x, y, i = 1; i <= q; i++) {
    scanf("%d%d", &x, &y);
    update(1, 1, 2 * (n - 1), x);
    update(1, 1, 2 * (n - 1), y);
    cout << tree[1].mx5 << endl;
  }
  return 0;
}
