# a = int(input())
# b = str(input())
# num = 0
# # while ")(" in b:
# b = b.replace(")(", "+")
# print(b)
# # while "()" in b:
# b = b.replace("()", "(1)")
# print(b)
# # while "))" in b or "((" in b:
# b = b.replace("))", ")+1)")
# # while "(" in b and ")" in b:
# #   b = b.replace("(", "1", 1)
# #   b = b.replace(")", "", 1)
# # while "1" in b:
# #   num += 1
# #   b = b.replace("1", "", 1)
# print(b)
# print(num)

a = int(input())
b = input()
count_open_bracket = 0
count_close_bracker = 0
result = 0
for i in b:
    if i == "(":
        count_open_bracket+=1
    if i == ")":
        count_close_bracker+=1
        if count_open_bracket > 0:
            count_close_bracker -= 1
            count_open_bracket -= 1
            result += 1
print(result)