from sys import stdin n, q = [int(x) for x in stdin.readline().rstrip().split()] s = stdin.readline().rstrip() indata = list(map(int, stdin.read().split())) bitree = [0 for i in range(n+1)] def btadd(ind,x): global bitree while ind <= n: bitree[ind] += x ind += ind & (-ind) def btsum(ind): val = 0 while ind > 0: val += bitree[ind] ind -= ind & (-ind) return val bracket = [0 for i in range(n)] if s[0] == ")": bracket[0] = 1 for i in range(1,n): if s[i] == ")": bracket[i] = 1 if bracket[i-1] == 0: btadd(i+1,1) offset = 0 for i in range(q): a = indata[offset] if a == 1: x = indata[offset + 1] - 1 offset += 2 if bracket[x] == 0: if x < n-1: if bracket[x+1] == 1: btadd(x+2,-1) if x > 0: if bracket[x-1] == 0: btadd(x+1,1) else: if x < n-1: if bracket[x+1] == 1: btadd(x+2,1) if x > 0: if bracket[x-1] == 0: btadd(x+1,-1) bracket[x] = bracket[x] ^ 1 else: l, r = indata[offset + 1], indata[offset + 2] offset += 3 ans = btsum(r) - btsum(l) print("{}".format(ans))