#include <iostream>
#include <bits/stdc++.h>
#include <vector>
using namespace std;

int main() {
    string abc_str;
    cin >> abc_str;

    if (abc_str.empty()) {
        cout << 0 << endl;
        return 0;
    }
    vector<int> xyz_str(26);
    for (int i = 0; i < 26; i++) {
        xyz_str[i] = i;
    }

    int n = abc_str.size();
    vector<int> sum(n, 0);

    for (int i = 0; i < 26; i++) {
        for (int j = 0; j < n; j++) {
            //if (j != i) {
            char target = 'a' + xyz_str[i];
            int diff = abs(abc_str[j] - target);
            sum[i] += min( diff,  26 - diff);
        }
    }

    int minDiff = sum[0];
    for (int i = 1; i < 26; i++) {
        minDiff = min(minDiff, sum[i]);
    }
    cout << minDiff << endl;
    return 0;
}
// 64 位输出请用 printf("%lld")