#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int n, q, a[maxn], maxi[maxn << 2], mini[maxn << 2], p1[maxn << 2],
    p2[maxn << 2], p3[maxn << 2], tag[maxn << 2];
void push_down(int p) {
  tag[(p << 1)] += tag[p];
  tag[(p << 1 | 1)] += tag[p];
  maxi[(p << 1)] += tag[p];
  maxi[(p << 1 | 1)] += tag[p];
  mini[(p << 1)] += tag[p];
  mini[(p << 1 | 1)] += tag[p];
  p1[(p << 1)] -= tag[p];
  p1[(p << 1 | 1)] -= tag[p];
  p2[(p << 1)] -= tag[p];
  p2[(p << 1 | 1)] -= tag[p];
  tag[p] = 0;
}
int max(int a, int b, int c) { return max(a, max(b, c)); }
int max(int a, int b, int c, int d) { return max(max(a, b), max(c, d)); }
void push_up(int p) {
  maxi[p] = max(maxi[(p << 1)], maxi[(p << 1 | 1)]);
  mini[p] = min(mini[(p << 1)], mini[(p << 1 | 1)]);
  p1[p] = max(p1[(p << 1)], p1[(p << 1 | 1)],
              maxi[(p << 1)] - 2 * mini[(p << 1 | 1)]);
  p2[p] = max(p2[(p << 1)], p2[(p << 1 | 1)],
              -2 * mini[(p << 1)] + maxi[(p << 1 | 1)]);
  p3[p] = max(p3[(p << 1)], p3[(p << 1 | 1)], maxi[(p << 1)] + p2[(p << 1 | 1)],
              p1[(p << 1)] + maxi[(p << 1 | 1)]);
}
void build(int p = 1, int l = 1, int r = n) {
  if (l == r) {
    maxi[p] = mini[p] = a[l];
    p1[p] = p2[p] = -a[l];
    p3[p] = 0;
    return;
  }
  int m = l + r >> 1;
  build((p << 1), l, m);
  build((p << 1 | 1), m + 1, r);
  push_up(p);
}
void modify(int nl, int nr, int val, int p = 1, int l = 1, int r = n) {
  if (nl <= l && r <= nr) {
    tag[p] += val;
    maxi[p] += val;
    mini[p] += val;
    p1[p] -= val;
    p2[p] -= val;
    return;
  }
  push_down(p);
  int m = l + r >> 1;
  if (nl <= m) modify(nl, nr, val, (p << 1), l, m);
  if (m < nr) modify(nl, nr, val, (p << 1 | 1), m + 1, r);
  push_up(p);
}
char s[maxn];
int main() {
  cin >> n >> q;
  n = n * 2 - 2;
  for (int i = 1; i <= n; i++) {
    char c;
    cin >> c;
    s[i] = c;
    if (c == '(')
      a[i] = a[i - 1] + 1;
    else
      a[i] = a[i - 1] - 1;
  }
  build();
  cout << p3[1] << '\n';
  while (q--) {
    int a, b;
    cin >> a >> b;
    if (a > b) swap(a, b);
    if (s[a] == '(') {
      modify(a, b - 1, -2);
    } else
      modify(a, b - 1, 2);
    swap(s[a], s[b]);
    cout << p3[1] << '\n';
  }
  return 0;
}
