Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.

Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture:

After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'.

Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it.
The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters.
To print the string from the first sample it would be optimal to perform the following sequence of rotations: 
 1.  from 'a' to 'z' (1 rotation counterclockwise), 1.  from 'z' to 'e' (5 clockwise rotations), 1.  from 'e' to 'u' (10 rotations counterclockwise), 1.  from 'u' to 's' (2 counterclockwise rotations).
zeus
18
map
35
ares
34
l
11
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv
99
gngvi
44
aaaaa
0
a
0
z
1
vyadeehhikklnoqrs
28
jjiihhhhgggfedcccbazyxx
21
fyyptqqxuciqvwdewyppjdzur
117
fqcnzmzmbobmancqcoalzmanaobpdse
368
zzzzzaaaaaaazzzzzzaaaaaaazzzzzzaaaazzzza
8
aucnwhfixuruefkypvrvnvznwtjgwlghoqtisbkhuwxmgzuljvqhmnwzisnsgjhivnjmbknptxatdkelhzkhsuxzrmlcpeoyukiy
644
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
8
nypjygrdtpzpigzyrisqeqfriwgwlengnezppgttgtndbrryjdl
421
pnllnnmmmmoqqqqqrrtssssuuvtsrpopqoonllmonnnpppopnonoopooqpnopppqppqstuuuwwwwvxzxzzaa
84
btaoahqgxnfsdmzsjxgvdwjukcvereqeskrdufqfqgzqfsftdqcthtkcnaipftcnco
666
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerrrrrrrrrrrrrrrrwwwwwwwwww
22
uyknzcrwjyzmscqucclvacmorepdgmnyhmakmmnygqwglrxkxhkpansbmruwxdeoprxzmpsvwackopujxbbkpwyeggsvjykpxh
643
gzwpooohffcxwtpjgfzwtooiccxsrrokezutoojdzwsrmmhecaxwrojcbyrqlfdwwrliiib
245
dbvnkktasjdwqsrzfwwtmjgbcxggdxsoeilecihduypktkkbwfbruxzzhlttrssicgdwqruddwrlbtxgmhdbatzvdxbbro
468
mdtvowlktxzzbuaeiuebfeorgbdczauxsovbucactkvyvemsknsjfhifqgycqredzchipmkvzbxdjkcbyukomjlzvxzoswumned
523
kkkkkkkaaaaxxaaaaaaaxxxxxxxxaaaaaaxaaaaaaaaaakkkkkkkkkaaaaaaannnnnxxxxkkkkkkkkaannnnnnna
130
dffiknqqrsvwzcdgjkmpqtuwxadfhkkkmpqrtwxyadfggjmpppsuuwyyzcdgghhknnpsvvvwwwyabccffiloqruwwyyzabeeehh
163
qpppmmkjihgecbyvvsppnnnkjiffeebaaywutrrqpmkjhgddbzzzywtssssqnmmljheddbbaxvusrqonmlifedbbzyywwtqnkheb
155
wvvwwwvvwxxxyyyxxwwvwwvuttttttuvvwxxwxxyxxwwwwwvvuttssrssstsssssrqpqqppqrssrsrrssrssssrrsrqqrrqpppqp
57
dqcpcobpcobnznamznamzlykxkxlxlylzmaobnaobpbnanbpcoaobnboaoboanzlymzmykylymylzlylymanboanaocqdqesfrfs
1236
nnnnnnnnnnnnnnnnnnnnaaaaaaaaaaaaaaaaaaaakkkkkkkkkkkkkkkkkkkkkkaaaaaaaaaaaaaaaaaaaaxxxxxxxxxxxxxxxxxx
49
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
0
cgilqsuwzaffilptwwbgmnttyyejkorxzflqvzbddhmnrvxchijpuwaeiimosxyycejlpquuwbfkpvbgijkqvxybdjjjptxcfkqt
331
ufsepwgtzgtgjssxaitgpailuvgqweoppszjwhoxdhhhpwwdorwfrdjwcdekxiktwziqwbkvbknrtvajpyeqbjvhiikxxaejjpte
692
uhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuh
1293
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvgggggggggggggggggggggggggggggggggggggggggggggggggg
16
lyidmjyzbszgiwkxhhpnnthfwcvvstueionspfrvqgkvngmwyhezlosrpdnbvtcjjxxsykixwnepbumaacdzadlqhnjlcejovple
616
etzqqbaveffalkdguunfmyyrzkccnxmlluxeasqmopxzfvlkbhipqdwjgrttoemruohgwukfisdhznqyvhswbbypoxgtxyappcrl
605
lizussgedcbdjhrbeskhgatyozvwwekanlggcstijrniivupmcoofbaxfqrxddyzzptwxcftlhajsmmkkriarrqtkoauhcqefyud
549
dvjuvgfdogpknmbowlsfjzcimnygbtjiucyeeroqwhmzwpjqxlbjkqawrdtmvxbiqufllfuqibxvmtdrwaqkjblxqjpwzmhwqore
688
eeycuijtbgynmiczjfslwobmnkpgodfgvujvduyfeqchuaoktqrrairkkmmsjahltfcxwtpzzyddxrqfxabfoocmpuviinrjitsc
604
cgglnakewwvzoytaghksebrhjdbcdegssuzilrcppayxtgxopybbwshvyqnzhdsifkuwghourmeottrgjwdqpihbklvfzxpomqsa
572
aexullmxncckzryymfnuugdklaffevabqqztelpvojecljnhqldazdcaamubpenwxikysxxjjctvbndprsolzehywmgnvkgqvrfp
609
psnoieutsvvcwfhtnnphhxkwigzsbzyjmdiyl
223
aa
0
# # t = int(input())
# t = 1
# # # n, m = map(int, input().split())
# # # a = list(map(int, input().split()))
# # # a.sort()
# import math
# from collections import Counter

# a = []
# while t != 0:
#     # cook your dish here
#     n = int(input())
#     ans = 0
#     for i in range(1, n):
#         if n % i == 0:
#             ans += 1
#     print(ans)
#     t -= 1
def rotations_needed(ch1, ch2):
    # Calculate the minimum number of rotations needed to move from ch1 to ch2
    return min((ord(ch2) - ord(ch1)) % 26, (ord(ch1) - ord(ch2)) % 26)

def min_rotations_to_print(name):
    # Initialize the total number of rotations to 0
    total_rotations = 0

    # Set the initial pointer to 'a'
    current_char = 'a'

    for ch in name:
        # Calculate the rotations needed to move from current_char to ch
        rotations = rotations_needed(current_char, ch)

        # Add the rotations to the total
        total_rotations += rotations

        # Update the current_char
        current_char = ch

    return total_rotations

# Read the input string
name = input()

# Calculate the minimum rotations needed
min_rotations = min_rotations_to_print(name)

# Print the result
print(min_rotations)
