#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100;
char ch[N];
int tot[N];
int max(int a, int b, int c) { return max(a, max(b, c)); }
int max(int a, int b, int c, int d) { return max(max(a, b), max(c, d)); }
struct Node {
  int l, r, lazy;
  int A, B, AB, BC, ABC;
  Node *left, *right;
  Node(int l = 0, int r = 0, int lazy = 0) : l(l), r(r), lazy(lazy){};
  void initialization(int value) {
    A = value;
    B = -2 * value;
    AB = A + B;
    BC = B + A;
    ABC = A + B + A;
    left = right = NULL;
  }
  void update() {
    A = max(left->A, right->A);
    B = max(left->B, right->B);
    AB = max(left->AB, right->AB, left->A + right->B);
    BC = max(left->BC, right->BC, left->B + right->A);
    ABC = max(left->ABC, right->ABC, left->AB + right->A, left->A + right->BC);
  }
  void down() {
    A += lazy;
    B += -2 * lazy;
    AB += -lazy;
    BC += -lazy;
    if (l != r) {
      left->lazy += lazy;
      right->lazy += lazy;
    }
    lazy = 0;
  }
  void lazyUpdate(int i, int j, int value) {
    down();
    if (i > r || j < l) return;
    if (i <= l && r <= j) {
      lazy = value;
      down();
      return;
    }
    left->lazyUpdate(i, j, value);
    right->lazyUpdate(i, j, value);
    update();
  }
  void show() {
    cout << l << ' ' << r << ' ' << A << ' ' << B << ' ' << ABC << '\n';
    if (l != r) {
      left->show();
      right->show();
    }
  }
} tree;
Node *build(int l, int r) {
  Node *node = new Node(l, r);
  if (l == r) {
    node->initialization(tot[l]);
    return node;
  }
  int mid = l + r >> 1;
  node->left = build(l, mid);
  node->right = build(mid + 1, r);
  node->update();
  return node;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, q;
  cin >> n >> q;
  int current = 0;
  n = 2 * (n - 1);
  for (int i = 1; i <= n; ++i) {
    cin >> ch[i];
    tot[i] = tot[i - 1] + (ch[i] == '(' ? 1 : -1);
  }
  Node *seg = build(1, n);
  int dia = seg->ABC;
  cout << dia << '\n';
  for (int x, y; q; q--) {
    cin >> x >> y;
    if (x > y) swap(x, y);
    if (ch[x] == ch[y]) {
      cout << dia;
      continue;
    }
    seg->lazyUpdate(x, y - 1, ch[x] == '(' ? -2 : 2);
    dia = seg->ABC;
    swap(ch[x], ch[y]);
    cout << dia << '\n';
  }
}
