#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
string s;
cin >> s;
int ans = 1e9;
for (char i = 'a'; i <= 'z'; ++i) {
int cost = 0;
for (char &x : s) {
int a = i - x;
int b = x - i;
if (a < 0) a += 26;
if (b < 0) b += 26;
cost += min(a, b);
}
ans = min(ans, cost);
}
cout << ans << '\n';
return 0;
}