#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
const int oo = 1e9 + 7;
int n, q;
int t[N];
string s;
struct Node {
  int mn, mx, pre, suf, tot;
  Node() {}
  Node(int mn, int mx, int pre, int suf, int tot)
      : mn(mn), mx(mx), pre(pre), suf(suf), tot(tot) {}
  Node operator+(const Node &Other) const {
    Node res;
    res.mn = min(mn, Other.mn);
    res.mx = max(mx, Other.mx);
    res.pre = max(mx - 2 * Other.mn, max(pre, Other.pre));
    res.suf = max(-2 * mn + Other.mx, max(suf, Other.suf));
    res.tot = max(max(pre + Other.mx, mx + Other.suf), max(tot, Other.tot));
    return res;
  }
};
struct segTree {
  Node tree[N << 3];
  int lazy[N << 3];
  void Build(int first, int low, int high) {
    if (low == high) {
      tree[first] = Node(t[low], t[low], -t[low], -t[low], 0);
    } else {
      int mid = low + high >> 1;
      Build(first << 1, low, mid);
      Build(first << 1 | 1, mid + 1, high);
      tree[first] = tree[2 * first] + tree[2 * first + 1];
    }
  }
  void Lazy(int first) {
    tree[first].mn += lazy[first];
    tree[first].mx += lazy[first];
    tree[first].pre -= lazy[first];
    tree[first].suf -= lazy[first];
    lazy[2 * first] += lazy[first];
    lazy[2 * first + 1] += lazy[first];
    lazy[first] = 0;
  }
  void Update(int first, int l, int r, int i, int j, int val) {
    Lazy(first);
    if (l > j || r < i) return;
    if (l >= i && r <= j) {
      lazy[first] += val;
      Lazy(first);
      return;
    }
    int mid = l + r >> 1;
    Update(2 * first, l, mid, i, j, val);
    Update(2 * first + 1, mid + 1, r, i, j, val);
    tree[first] = tree[2 * first] + tree[2 * first + 1];
  }
} IT;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  if (fopen("test.inp", "r"))
    freopen("test.inp", "r", stdin), freopen("test.out", "w", stdout);
  cin >> n >> q;
  cin >> s;
  s = ' ' + s;
  t[0] = 1;
  n = 2 * n - 2;
  for (int i = 1; i <= n; i++) {
    char ch = s[i];
    t[i] = t[i - 1];
    if (ch == '(')
      t[i]++;
    else
      t[i]--;
  }
  IT.Build(1, 1, n);
  cout << IT.tree[1].tot << endl;
  for (int i = 1; i <= q; i++) {
    int u, v;
    cin >> u >> v;
    if (s[u] == '(')
      IT.Update(1, 1, n, u, n, -2);
    else
      IT.Update(1, 1, n, u, n, 2);
    if (s[v] == '(')
      IT.Update(1, 1, n, v, n, -2);
    else
      IT.Update(1, 1, n, v, n, 2);
    swap(s[u], s[v]);
    cout << IT.tree[1].tot << endl;
  }
}
