#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f;
const int N = 2e5 + 10;
const long long mod = 1e9 + 7;
const bool debug = false;
struct Node {
  int ans, r, l, mx, mi, lazy;
  void add(int x) { r -= x, l -= x, mx += x, mi += x, lazy += x; }
  void pri(int o) {
    printf("----------%d--------\n", o);
    printf("ans = %d, r = %d, l = %d, mx = %d, mi = %d, lazy = %d\n", ans, r, l,
           mx, mi, lazy);
  }
} node[N << 2];
int v[N];
char s[N];
void push_up(int o) {
  node[o].ans = max({node[o << 1].ans, node[o << 1 | 1].ans,
                     node[o << 1].mx + node[o << 1 | 1].r,
                     node[o << 1 | 1].mx + node[o << 1].l});
  node[o].l = max({node[o << 1].l, node[o << 1 | 1].l,
                   node[o << 1].mx - node[o << 1 | 1].mi * 2});
  node[o].r = max({node[o << 1].r, node[o << 1 | 1].r,
                   node[o << 1 | 1].mx - node[o << 1].mi * 2});
  node[o].mi = min(node[o << 1].mi, node[o << 1 | 1].mi);
  node[o].mx = max(node[o << 1].mx, node[o << 1 | 1].mx);
}
void push_down(int o) {
  node[o << 1].add(node[o].lazy);
  node[o << 1 | 1].add(node[o].lazy);
  node[o].lazy = 0;
}
void build(int l, int r, int o) {
  if (l == r) {
    node[o].ans = 0, node[o].add(v[l]);
    if (debug) node[o].pri(o);
    return;
  }
  int mid = l + r >> 1;
  build(l, mid, o << 1);
  build(mid + 1, r, o << 1 | 1);
  push_up(o);
  if (debug) node[o].pri(o);
}
void update(int ll, int x, int l, int r, int o) {
  if (ll <= l) {
    node[o].add(x);
    if (debug) node[o].pri(o);
    return;
  }
  if (node[o].lazy) push_down(o);
  int mid = l + r >> 1;
  if (ll <= mid) update(ll, x, l, mid, o << 1);
  update(ll, x, mid + 1, r, o << 1 | 1);
  push_up(o);
  if (debug) node[o].pri(o);
}
int main() {
  int n, up, q;
  scanf("%d%d", &n, &q);
  scanf("%s", s + 2);
  s[1] = '(', s[n << 1] = ')';
  for (int i = 1; i <= n * 2; ++i) {
    v[i] = '(' == s[i] ? 1 : -1;
    v[i] += v[i - 1];
  }
  up = n * 2 - 1;
  build(1, up, 1);
  printf("%d\n", node[1].ans);
  for (int i = 1, u, v; i <= q; ++i) {
    scanf("%d%d", &u, &v);
    u++, v++;
    if (debug) puts("++++++++++++++++++++"), puts(s + 2);
    if (s[u] != s[v]) {
      if (s[u] == '(')
        update(u, -2, 1, up, 1), update(v, 2, 1, up, 1);
      else
        update(u, 2, 1, up, 1), update(v, -2, 1, up, 1);
      swap(s[u], s[v]);
    }
    printf("%d\n", node[1].ans);
  }
  return 0;
}
