import sys

def solve():
    s = str(input())
    cnt = [0] * 26
    for c in s:
        cnt[ord(c) - ord('a')] += 1 # ord():把字母映射为数字,返回一个Unicode编码值
    min_ops = float('inf')  # 初始化最小操作为无穷
    for target in range(26):
        total = 0
        for c in range(26):
            if cnt[c] == 0:
                continue
            # 环形路径最小值
            d = abs(c - target) # abs():取绝对值
            d = min(d,26 - d)   # min():取最小值
            total += cnt[c] * d
        if total < min_ops:
            min_ops = total
    print(min_ops)

solve()