#include <bits/stdc++.h>
using namespace std;
int n, m;
string s;
struct Node {
  int delta, _min, _max, max_lv, max_rv, max_lvr;
  void merge(int l, int r);
} ans[1000000];
void Node::merge(int l, int r) {
  delta = ans[l].delta + ans[r].delta;
  _min = min(ans[l]._min, ans[l].delta + ans[r]._min);
  _max = max(ans[l]._max, ans[l].delta + ans[r]._max);
  max_lv = max(max(ans[l].max_lv, ans[r].max_lv - ans[l].delta),
               ans[l]._max - 2 * ans[r]._min - 2 * ans[l].delta);
  max_rv = max(max(ans[l].max_rv, ans[r].max_rv - ans[l].delta),
               ans[r]._max - 2 * ans[l]._min + ans[l].delta);
  max_lvr = 0;
  max_lvr = max(max_lvr, ans[l].max_lvr);
  max_lvr = max(max_lvr, ans[l].max_lv + ans[r]._max + ans[l].delta);
  max_lvr = max(max_lvr, ans[l]._max + ans[r].max_rv - ans[l].delta);
  max_lvr = max(max_lvr, ans[r].max_lvr);
}
void build(int l, int r, int o) {
  if (l == r) {
    ans[o]._min = ans[o]._max = ans[o].delta = (s[l - 1] == ')' ? -1 : 1);
    ans[o].max_lv = ans[o].max_rv = -ans[o].delta;
    ans[o].max_lvr = 0;
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, o << 1);
  build(mid + 1, r, o << 1 | 1);
  ans[o].merge(o << 1, o << 1 | 1);
}
void update(int now, int l, int r, int o) {
  if (l == r) {
    ans[o]._min = ans[o]._max = ans[o].delta = (s[l - 1] == ')' ? -1 : 1);
    ans[o].max_lv = ans[o].max_rv = -ans[o].delta;
    ans[o].max_lvr = 0;
    return;
  }
  int mid = (l + r) >> 1;
  if (now <= mid)
    update(now, l, mid, o << 1);
  else
    update(now, mid + 1, r, o << 1 | 1);
  ans[o].merge(o << 1, o << 1 | 1);
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  n = 2 * n - 2;
  cin >> s;
  build(1, n, 1);
  int x, y;
  cout << ans[1].max_lvr << endl;
  while (m--) {
    cin >> x >> y;
    swap(s[x - 1], s[y - 1]);
    if (s[x - 1] != s[y - 1]) {
      update(x, 1, n, 1);
      update(y, 1, n, 1);
    }
    cout << ans[1].max_lvr << endl;
  }
}
