#!python # -*- coding: utf-8 -*- N = int(input()) S = input() R = 0 L = 0 for i, c in enumerate(S): if c == '(': L += len(S) - i else: R += len(S) - i if S[0] == ')': print(min(R, L) * 2 - 2) else: print(min(R, L) * 2)