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