#include <bits/stdc++.h>
using namespace std;
string m;
char pre, nexht;
long long ans;
int main() {
  cin >> m;
  pre = 'a';
  for (int i = 0; i < m.length(); i++) {
    nexht = m[i];
    ans = ans + min(abs((nexht + 26) - pre),
                    min((abs(nexht - pre)), abs((pre + 26) - nexht)));
    pre = nexht;
  }
  cout << ans;
  return 0;
}
