s = list(map(int,input().split()))

def recur(beg, en, c):
    if(en-beg==1):
        return s[beg]!=c
    if(en==beg):
        return 0
    mid,d = (beg+en)//2,chr(ord(c) + 1)
    left, right = 0,0
    for i in range(beg,mid+1):
        left+=1 if s[i]!=c else 0
    for i in range(mid,en):
        right+=1 if s[i]!=c else 0
    left += recur(beg,mid,d )
    right += recur(mid+1,en,d)
    return min(left,right)

print(recur(0,len(s),'a'))
