N = int(input()) S = input() R, M = map(int, input().split()) def solve(): if N % 2 == 1: return -1 lt = S.count('(') rt = S.count(')') if lt == rt: return 0 return abs(lt - rt) * M // 2 ans = solve() print(ans)