import sys input = sys.stdin.readline class Fenwick_Tree: def __init__(self, n): self._n = n self.data = [0] * n def add(self, p, x): assert 0 <= p < self._n p += 1 while p <= self._n: self.data[p - 1] += x p += p & -p def sum(self, l, r): assert 0 <= l <= r <= self._n return self._sum(r) - self._sum(l) def _sum(self, r): s = 0 while r > 0: s += self.data[r - 1] r -= r & -r return s def get_size(self, x): x = self.find(x) while r > 0: s += self.data[r - 1] r -= r & -r return s def get(self, k): k += 1 x, r = 0, 1 while r < self._n: r <<= 1 len = r while len: if x + len - 1 < self._n: if self.data[x + len - 1] < k: k -= self.data[x + len - 1] x += len len >>= 1 return x N, Q = map(int, input().split()) S = [int(s == ")") for s in input()] S.pop() T = Fenwick_Tree(N) for i in range(1, N): if S[i] and not S[i - 1]: T.add(i, 1) for _ in range(Q): q = list(map(int, input().split())) if q[0] == 1: i = q[1] - 1 if S[i] and i: if S[i - 1] == 0: T.add(i, -1) if S[i] == 0 and i < N - 1: if S[i + 1]: T.add(i + 1, -1) S[i] = 1 - S[i] if S[i] and i: if S[i - 1] == 0: T.add(i, 1) if S[i] == 0 and i < N - 1: if S[i + 1]: T.add(i + 1, 1) else: l, r = q[1:] l -= 1 ans = T.sum(l, r) if S[l] and l: if S[l - 1] == 0: ans -= 1 print(ans)