#include <bits/stdc++.h>
using namespace std;
const long long llINF = 9223372036854775807;
const int INF = 2147483647;
const int maxn = 2e5 + 7;
const int maxm = 5e4 + 7;
const long long mod = 1e9 + 7;
const double pi = acos(-1.0);
const double eps = 1e-12;
int n, q;
char s[maxn];
int u[maxn];
struct SegmentTree {
  int l, r;
  int mini, maxi, minimaxi, maximini, diameter, lazy;
} tree[maxn << 2];
void push_up(int root) {
  tree[root].mini = min(tree[root << 1].mini, tree[root << 1 | 1].mini);
  tree[root].maxi = max(tree[root << 1].maxi, tree[root << 1 | 1].maxi);
  tree[root].minimaxi =
      max(max(tree[root << 1].minimaxi, tree[root << 1 | 1].minimaxi),
          -2 * tree[root << 1].mini + 1 * tree[root << 1 | 1].maxi);
  tree[root].maximini =
      max(max(tree[root << 1].maximini, tree[root << 1 | 1].maximini),
          +1 * tree[root << 1].maxi - 2 * tree[root << 1 | 1].mini);
  tree[root].diameter =
      max(max(tree[root << 1].diameter, tree[root << 1 | 1].diameter),
          max(tree[root << 1].maximini + tree[root << 1 | 1].maxi,
              tree[root << 1].maxi + tree[root << 1 | 1].minimaxi));
  tree[root].diameter =
      max(tree[root].diameter, tree[root].maxi - tree[root].mini);
}
void update(int root, int val) {
  tree[root].mini += val;
  tree[root].maxi += val;
  tree[root].minimaxi -= val;
  tree[root].maximini -= val;
  tree[root].lazy += val;
}
void push_down(int root) {
  if (tree[root].lazy == 0) return;
  update(root << 1, tree[root].lazy);
  update(root << 1 | 1, tree[root].lazy);
  tree[root].lazy = 0;
}
void build(int root, int l, int r) {
  tree[root].l = l;
  tree[root].r = r;
  if (l == r) {
    tree[root].mini = tree[root].maxi = u[l];
    tree[root].diameter = 0;
    tree[root].minimaxi = tree[root].maximini = -1e9;
    tree[root].lazy = 0;
    return;
  } else {
    int mid = (l + r) >> 1;
    build(root << 1, l, mid);
    build(root << 1 | 1, mid + 1, r);
    push_up(root);
  }
  return;
}
void change(int root, int l, int r, int val) {
  if (l > tree[root].r || r < tree[root].l) return;
  if (tree[root].l >= l && tree[root].r <= r) {
    update(root, val);
    return;
  }
  push_down(root);
  int mid = (tree[root].l + tree[root].r) >> 1;
  if (l <= mid) change(root << 1, l, r, val);
  if (r > mid) change(root << 1 | 1, l, r, val);
  push_up(root);
  return;
}
int main(int argc, char const *argv[]) {
  scanf("%d%d", &n, &q);
  scanf("%s", s + 1);
  for (int i = 1; i <= 2 * (n - 1); i++)
    u[i] = u[i - 1] + (s[i] == '(' ? 1 : -1);
  build(1, 1, 2 * (n - 1));
  printf("%d\n", tree[1].diameter);
  while (q--) {
    int l, r;
    scanf("%d%d", &l, &r);
    if (l > r) swap(l, r);
    if (s[l] == s[r])
      ;
    else if (s[l] == '(')
      change(1, l, r - 1, -2);
    else if (s[l] == ')')
      change(1, l, r - 1, 2);
    swap(s[l], s[r]);
    printf("%d\n", tree[1].diameter);
  }
  return 0;
}
