N = int(input()) S = input() if N % 2 == 1: print(-1) else: print(abs(N // 2 - S.count("(")))