#include <bits/stdc++.h>
using namespace std;
struct Node {
  int sum;
  int max_depth;
  int min_depth;
  int max_max_depth_minus_2_min_depth;
  int max_max_depth_minus_2_min_depth_2;
  int max_length;
  Node() {
    sum = 0;
    max_depth = 0;
    min_depth = 0;
    max_max_depth_minus_2_min_depth = 0;
    max_length = 0;
  };
  Node(char c, int index);
  int left;
  int right;
};
const int SZ = 1 << 18;
Node tree[SZ * 2];
Node::Node(char c, int index) {
  if (c == '(') {
    sum = 1;
    min_depth = 0;
    max_depth = 1;
    max_max_depth_minus_2_min_depth = 0;
    max_max_depth_minus_2_min_depth_2 = 1;
  } else {
    sum = -1;
    min_depth = -1;
    max_depth = 0;
    max_max_depth_minus_2_min_depth = -1;
    max_max_depth_minus_2_min_depth_2 = -1;
  }
  max_length = 1;
  this->left = index;
  this->right = index;
}
void Merge(const Node& a, const Node& b, Node& result) {
  result.sum = a.sum + b.sum;
  result.max_depth = max(a.max_depth, a.sum + b.max_depth);
  result.min_depth = min(a.min_depth, a.sum + b.min_depth);
  result.max_max_depth_minus_2_min_depth =
      max(a.max_max_depth_minus_2_min_depth,
          b.max_max_depth_minus_2_min_depth - a.sum);
  result.max_max_depth_minus_2_min_depth =
      max(result.max_max_depth_minus_2_min_depth,
          a.max_depth - 2 * (a.sum + b.min_depth));
  result.max_max_depth_minus_2_min_depth_2 =
      max(a.max_max_depth_minus_2_min_depth_2,
          b.max_max_depth_minus_2_min_depth_2 - a.sum);
  result.max_max_depth_minus_2_min_depth_2 =
      max(result.max_max_depth_minus_2_min_depth_2,
          (a.sum + b.max_depth) - 2 * a.min_depth);
  result.max_length = max(a.max_length, b.max_length);
  result.max_length = max(result.max_length, a.max_max_depth_minus_2_min_depth +
                                                 (a.sum + b.max_depth));
  result.max_length = max(result.max_length, result.max_depth);
  result.max_length =
      max(result.max_length,
          a.max_depth - a.sum + b.max_max_depth_minus_2_min_depth_2);
  result.left = a.left;
  result.right = max(a.right, b.right);
}
string s;
void Update(int index, char c) {
  tree[index + SZ] = Node(c, index);
  index += SZ;
  while (index != 1) {
    index >>= 1;
    Merge(tree[index * 2], tree[index * 2 + 1], tree[index]);
  }
}
int main() {
  int n, q, x, y;
  cin >> n >> q;
  cin >> s;
  for (int i = 0; i < s.length(); i++) {
    Update(i, s[i]);
  }
  cout << tree[1].max_length << endl;
  for (int i = 0; i < q; i++) {
    cin >> x >> y;
    x--, y--;
    swap(s[x], s[y]);
    Update(x, s[x]);
    Update(y, s[y]);
    cout << tree[1].max_length << endl;
  }
  return 0;
}
