#include <bits/stdc++.h>
using namespace std;
int main() {
//freopen("cubes.in", "r", stdin);
//freopen ("output.txt","w",stdout);
int t = 1;
// cin >> t;
for (int j = 0; j < t; j++) {
string s;
cin >> s;
char ch = 'a';
int ans = 1e9;
for(char c = 'a'; c <= 'z'; c++) {
int x = 0;
for(char l : s) {
x += abs(l - c);
}
ans = min(ans, x);
}
cout << ans;
}
return 0;
}