#include <bits/stdc++.h>
using namespace std;
#include<iostream>
#define Dark ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define endl "\n"
int dff(char a,char b){//short for dif between letters
int k;
k=abs(a-b);
k=min(k,26-k); return k;
}
int main(){ Dark
string s; cin>>s;s='a'+s;
int n=s.size(),v=0,x=0,k=0,ans=0;
for(int i=1;i<n;i++){
ans+=dff(s[i-1],s[i]);
} cout<<ans;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNpbmNsdWRlPGlvc3RyZWFtPgojZGVmaW5lIERhcmsgaW9zOjpzeW5jX3dpdGhfc3RkaW8oMCk7Y2luLnRpZShOVUxMKTtjb3V0LnRpZShOVUxMKTsKI2RlZmluZSBsbCBsb25nIGxvbmcKI2RlZmluZSBlbmRsICJcbiIKaW50IGRmZihjaGFyIGEsY2hhciBiKXsvL3Nob3J0IGZvciBkaWYgYmV0d2VlbiBsZXR0ZXJzCiAgICBpbnQgazsKICAgIGs9YWJzKGEtYik7CiAgICBrPW1pbihrLDI2LWspOyByZXR1cm4gazsKfQoKCmludCBtYWluKCl7IERhcmsKc3RyaW5nIHM7IGNpbj4+cztzPSdhJytzOwppbnQgbj1zLnNpemUoKSx2PTAseD0wLGs9MCxhbnM9MDsKCmZvcihpbnQgaT0xO2k8bjtpKyspewogICAgCiAgICBhbnMrPWRmZihzW2ktMV0sc1tpXSk7Cn0gY291dDw8YW5zOwp9