import sys input = sys.stdin.readline N=int(input()) S=input().strip() R,M=map(int,input().split()) if N%2!=0: print(-1) exit() x=0 y=0 for s in S: if s=="(": x+=1 else: y+=1 ANS=(max(x,y)-min(x,y))//2 print(ANS)