import math
s = input()
s = s.strip()
size = len(s)
count = 0
mini = 100000
base = None
for i in s:
count = 0
base = i
for j in s:
diff = ord(base) - ord(j)
count = count + abs(diff)
if mini > count:
mini = count
print(mini)