#include<iostream>
#include<cmath>
using namespace std;
#include<cstring>
int main()
{
int sum = 0;
char ch[100];
cin >> ch;
char begin = 'a';
for (int i = 0; i <strlen(ch); i++)
{
int l1 = abs(ch[i] - begin);
int l2 = 26 - abs(l1);
sum += min(l1, l2);
begin = ch[i];
}
cout << sum << endl;
return 0;
}