#include <bits/stdc++.h>
using namespace std;
string letters("abcdefghijklmnopqrstuvwxyz");
int main() {
  char curlet = 'a';
  string word;
  cin >> word;
  int sum = 0;
  for (int i = 0; i < word.size(); i++) {
    int cw = abs((word[i] - 'a' + 1) - (curlet - 'a' + 1)),
        ccw = 26 - abs((word[i] - 'a' + 1) - (curlet - 'a' + 1));
    sum += min(cw, ccw);
    curlet = word[i];
  }
  cout << sum << endl;
  return 0;
}
