#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pb push_back
#define md ((st + nd) >> 1)
#define lc (1 + (idx << 1))
#define rc (2 + (idx << 1))
const int N = 100005;
char s[N];
int main() {
scanf("%s", s);
int n = strlen(s);
int res = 1e9;
for (char c = 'a'; c <= 'z'; c++) {
int cost = 0;
for (int i = 0; i < n; i++) {
cost += abs(c - s[i]);
}
res = min(res, cost);
}
printf("%d", res);
return 0;
}