#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &item) {
  out << '(' << item.first << ", " << item.second << ')';
  return out;
}
template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  for (const auto &item : v) out << item << ' ';
  return out;
}
const int NMAX = 200010;
struct lol {
  int lv;
  int v0;
  int v1;
  int v2;
  int v3;
  int v4;
  lol(int v = 0) {
    lv = v;
    v0 = v;
    v1 = v;
    v2 = -v;
    v3 = -v;
    v4 = 0;
  }
  friend ostream &operator<<(ostream &out, const lol &a) {
    return out << '(' << a.lv << ' ' << a.v0 << ' ' << a.v1 << ' ' << a.v2
               << ' ' << a.v3 << ' ' << a.v4 << ')';
  }
};
int m;
string s;
lol st[NMAX << 2];
int val(char ch) { return (ch == '(' ? 1 : -1); }
lol combine(const lol &a, const lol &b) {
  lol ret;
  ret.lv = a.lv + b.lv;
  ret.v0 = min(a.v0, a.lv + b.v0);
  ret.v1 = max(a.v1, a.lv + b.v1);
  ret.v2 = max(max(a.v2, -a.lv + b.v2), a.v1 - 2 * (a.lv + b.v0));
  ret.v3 = max(max(a.v3, -a.lv + b.v3), -2 * a.v0 + (a.lv + b.v1));
  ret.v4 = max(max(a.v4, b.v4), max(a.v1 - a.lv + b.v3, a.v2 + a.lv + b.v1));
  return ret;
}
void build(int node, int l, int r) {
  if (l == r) return void(st[node] = lol(val(s[l])));
  int mid = (l + r) / 2;
  build(2 * node, l, mid);
  build(2 * node + 1, mid + 1, r);
  st[node] = combine(st[2 * node], st[2 * node + 1]);
}
void update(int node, int l, int r, int p) {
  if (l == r) return void(st[node] = lol(val(s[p])));
  int mid = (l + r) / 2;
  if (p <= mid)
    update(2 * node, l, mid, p);
  else
    update(2 * node + 1, mid + 1, r, p);
  st[node] = combine(st[2 * node], st[2 * node + 1]);
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  m = 2 * n - 2;
  cin >> s;
  build(1, 0, m - 1);
  cout << st[1].v4 << '\n';
  while (q--) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    swap(s[a], s[b]);
    update(1, 0, m - 1, a);
    update(1, 0, m - 1, b);
    cout << st[1].v4 << '\n';
  }
  return 0;
}
