N = int(input()) S = input() R,M = list(map(int,input().split())) if(N%2 == 1): print("-1") exit() else: print(abs(N//2 - S.count("(")))