#include <bits/stdc++.h>
using namespace std;
template <typename T>
using V = vector<T>;
template <typename T>
using VV = vector<V<T>>;
template <typename T>
using Mi = map<long long, T>;
template <typename T>
using MMi = map<long long, Mi<T>>;
const double PI = 3.141592653589793238463;
void cinArr(vector<long long> &arr) {
  for (int i = 0; i < arr.size(); i++) {
    cin >> arr[i];
  }
}
void cinArr(V<int> &arr) {
  for (int i = 0; i < arr.size(); i++) {
    cin >> arr[i];
  }
}
int xx[4] = {1, -1, 0, 0};
int yy[4] = {0, 0, 1, -1};
vector<long long> prim;
vector<long long> prims;
void er() {
  long long n = 1e6;
  prim = vector<long long>(n + 1);
  for (int i = 0; i <= n; i++) {
    prim[i] = i;
  }
  for (long long i = 2; i <= n; i++) {
    if (prim[i] == i) {
      prims.push_back(i);
      for (long long j = i * i; j <= n; j += i) {
        if (prim[j] == j) {
          prim[j] = i;
        }
      }
    }
  }
}
class Node {
 private:
  long long value = 0;
  long long minVal = 0;
  long long maxVal = 0;
  long long maxLv = 0;
  long long maxRv = 0;
  long long ans = 0;
  void left() {
    value = 1;
    minVal = 0;
    maxVal = 1;
    maxLv = 0;
    maxRv = 1;
    ans = 1;
  }
  void right() {
    value = -1;
    minVal = -1;
    maxVal = 0;
    maxLv = 2;
    maxRv = 1;
    ans = 1;
  }
  void merge() {
    long long add = lChildren->value;
    value = add + rChildren->value;
    minVal = min(lChildren->minVal, add + rChildren->minVal);
    maxVal = max(lChildren->maxVal, add + rChildren->maxVal);
    maxLv = max({lChildren->maxLv, rChildren->maxLv - add,
                 lChildren->maxVal - 2 * (rChildren->minVal + add)});
    maxRv = max({lChildren->maxRv, rChildren->maxRv - add,
                 rChildren->maxVal + add - 2 * lChildren->minVal});
    ans = max({lChildren->ans, rChildren->ans,
               lChildren->maxLv + rChildren->maxVal + add,
               rChildren->maxRv - add + lChildren->maxVal});
  }

 public:
  long long l;
  long long r;
  Node *lChildren;
  Node *rChildren;
  long long getValue() { return value; }
  long long getAns() { return ans; }
  long long getValue(long long ind) {
    if (l == r) {
      return getValue();
    }
    long long mid = (l + r) / 2;
    if (ind <= mid) {
      return lChildren->getValue(ind);
    } else {
      return rChildren->getValue(ind);
    }
  }
  Node(long long l, long long r, vector<long long> &arr) {
    this->l = l;
    this->r = r;
    if (l == r) {
      if (arr[l] == 1) {
        left();
      } else {
        right();
      }
    } else {
      long long mid = (l + r) / 2;
      lChildren = new Node(l, mid, arr);
      rChildren = new Node(mid + 1, r, arr);
      merge();
    }
  }
  void update(long long l, long long r, long long value) {
    if (l == this->l && r == this->r) {
      if (value == 1) {
        left();
      } else {
        right();
      }
      return;
    }
    long long mid = (this->l + this->r) / 2;
    if (l <= mid) {
      lChildren->update(l, min(mid, r), value);
    }
    if (r > mid) {
      rChildren->update(max(mid + 1, l), r, value);
    }
    merge();
  }
};
long long gcd(long long a, long long b) {
  if (a < b) {
    swap(a, b);
  }
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
long long gcd(long long a, long long b, long long &x, long long &y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  long long x1, y1;
  long long d = gcd(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return d;
}
long long nok(long long a, long long b) {
  long long nnod = gcd(a, b);
  long long ans = a / nnod * b;
  return ans;
}
pair<long long, long long> zero = {-1, -1};
long long divup(long long a, long long b) {
  if (a % b == 0) {
    return a / b;
  } else {
    return a / b + 1;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, q;
  cin >> n >> q;
  vector<long long> arr(2 * (n - 1));
  for (int i = 0; i < 2 * (n - 1); i++) {
    char c;
    cin >> c;
    if (c == '(') {
      arr[i] = 1;
    } else {
      arr[i] = -1;
    }
  }
  Node tree(0, arr.size() - 1, arr);
  cout << tree.getAns() << '\n';
  for (int i = 0; i < q; i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    long long c = arr[a];
    arr[a] = arr[b];
    arr[b] = c;
    tree.update(a, a, arr[a]);
    tree.update(b, b, arr[b]);
    cout << tree.getAns() << '\n';
  }
  return 0;
}
