#include <bits/stdc++.h>
using namespace std;
string word;
int sum;
int main() {
  cin >> word;
  char last = 'a';
  for (int i = 0; i < word.size(); i++) {
    int d = abs((int)last - (int)word[i]);
    int c = abs(26 - d);
    sum += min(c, d);
    last = word[i];
  }
  cout << sum << endl;
}
