#include <iostream>
#include <algorithm>
#include <iterator>
#include <math.h>
#include <vector>
#include <set>
#include <map>
using namespace std;
int main() {
string s;
int n = 1e5, c = 0;
cin >> s;
int f[27] = { 0 };
for (int i = 0; i < s.size(); i++) {
f[s[i] - 'a']++;
}
for (int i = 0; i < 27; i++) {
c = 0;
for (int j = 0; j < 27; j++) {
if (i == j)continue;
else {
c += f[j] * abs(j - i);
}
}
n = min(n, c);
}
cout << n;
return 0;
}