# Problem statement and public data:
# https://cw.felk.cvut.cz/courses/a4b33alg/task.php?task=searchnodes

import math

NIL = -1;
def maketree(inp_str, root, K, L, R, P):
    currnode = root
    prevNode = 0  # remember the previous node to be able to establish link to the parent
    P[root] = NIL # extra, does not fit into the loop

    goLeft = True # determines where is the next child

    i = 1 # index of the character in the input string
    while i < len(inp_str):
        inp_char = inp_str[i]

        if inp_char == '(' :   # going down
            prevNode += 1
            if goLeft:
                L[currnode] = prevNode
            else:
                R[currnode] = prevNode
                goLeft = True
            P[prevNode] = currnode
            currnode = prevNode

        if inp_char == ')':
            currnode = P[currnode]   # going up

        if inp_char.isdigit():  # decipher the key
            K[currnode] = ord(inp_char)-48;  j = i+1
            while inp_str[j].isdigit():
                K[currnode] = K[currnode]*10 + ord(inp_str[j]) - 48
                j = j + 1
            i = j-1
            goLeft = False

        i = i+1


def noOfSearchNodes(node, K, L, R):
    if node == NIL:
        return 0
    if L[node] == NIL:
        if R[node] == NIL:
            return 1;
        if K[node] >= K[R[node]]:
            return noOfSearchNodes(R[node], K, L, R)
        else:
            return 1 + noOfSearchNodes(R[node], K, L, R)
    else:  # L[root] != NIL
        if R[node] == NIL:
            if K[L[node]] >= K[node]:
                return noOfSearchNodes(L[node], K, L, R)
            else:
                return 1 + noOfSearchNodes(L[node], K, L, R)
        # case when both L and R children of nodes exist
        x = noOfSearchNodes(L[node], K, L, R) + noOfSearchNodes(R[node], K, L, R)
        if K[L[node]] >= K[node] or K[node] >= K[R[node]]:
            return x
        else:
            return 1 + x



# ----------------------------------------------------------------------------
#                M A I N
# ----------------------------------------------------------------------------

s = input()
K = [0] * 2*len(s); L = [-1] * 2*len(s); R = [-1] * 2*len(s); P = [-1] * 2*len(s)
maketree(s, 0, K, L, R, P)
res = noOfSearchNodes(0, K, L, R)
print(res)


'''
Example 1
(((10)40((25)30(35)))50((70(80(40)))60))

Example 2
(((70)60(50))40((30)20(10)))

Example 3
(((((20)12(14((((12)15)19)10(14))))16(17(((11)18)20(14(10)))))10(((10(16))19)18(19(20(17(17))))))16((11)13))



'''
