n = int(input()) s = input().strip() total = 0 left = 0 right = 0 for c in s: if c == '(': left += 1 else: right += 1 total += min(left, right) print(total * 2)