#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 30, Mod = 1e9 + 7;
const long long SQ = 330;
long long x[N << 2], y[N << 2], z[N << 2], xy[N << 2], yz[N << 2], xyz[N << 2],
    lazy[N << 2], a[N], n, q;
void Ass(int id, int val) {
  lazy[id] += val;
  x[id] += val;
  y[id] += val;
  z[id] += val;
  xy[id] -= val;
  yz[id] -= val;
  xyz[id] += val - val;
}
void Shift(int id) {
  Ass((id << 1), lazy[id]);
  Ass(((id << 1) | 1), lazy[id]);
  lazy[id] = 0;
}
void Comb(int id) {
  x[id] = max(x[(id << 1)], x[((id << 1) | 1)]);
  y[id] = min(y[(id << 1)], y[((id << 1) | 1)]);
  z[id] = max(z[(id << 1)], z[((id << 1) | 1)]);
  xy[id] = max({xy[(id << 1)], xy[((id << 1) | 1)],
                x[(id << 1)] - 2 * y[((id << 1) | 1)]});
  yz[id] = max({yz[(id << 1)], yz[((id << 1) | 1)],
                z[((id << 1) | 1)] - 2 * y[(id << 1)]});
  xyz[id] = max({xyz[(id << 1)], xyz[((id << 1) | 1)],
                 xy[(id << 1)] + z[((id << 1) | 1)],
                 x[(id << 1)] + yz[((id << 1) | 1)]});
}
void Add(int l, int r, int val, int id = 1, int b = 0, int e = n + n) {
  if (r <= b || e <= l) return;
  if (l <= b && e <= r) {
    Ass(id, val);
    return;
  }
  Shift(id);
  Add(l, r, val, (id << 1), b, ((b + e) >> 1));
  Add(l, r, val, ((id << 1) | 1), ((b + e) >> 1), e);
  Comb(id);
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> q;
  string s;
  cin >> s;
  long long cur = 0;
  for (int i = 0; i < n + n - 2; i++) {
    if (s[i] == '(')
      cur++;
    else
      cur--;
    Add(i, i + 1, cur);
  }
  cout << xyz[1] << '\n';
  while (q--) {
    long long l, r;
    cin >> l >> r;
    if (r < l) {
      l ^= r;
      r ^= l;
      l ^= r;
    }
    long long val = 2;
    if (s[l - 1] == '(') val -= 4;
    l--;
    r--;
    swap(s[l], s[r]);
    Add(l, r, val);
    cout << xyz[1] << '\n';
  }
}
