#!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 print(min(R, L) * 2)