import sys N = int(input()) S = input() R,M = map(int,input().split()) d = 0 for c in S: if c == "(": d += 1 else: d -= 1 d = abs(d) if d % 2 == 1: print (-1) else: print (d//2)