#include <bits/stdc++.h>
using namespace std;
int main() {
  char circularArr[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
                          'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                          's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
  char temp = 'a';
  string word;
  cin >> word;
  queue<char> myQueue;
  for (int i = 0; i < word.size(); i++) {
    myQueue.push(word[i]);
  }
  int minRotation = 0;
  int frontPointer = 0;
  int backPointer = 0;
  while (!myQueue.empty()) {
    int forward = 0;
    int backward = 0;
    while (circularArr[frontPointer] != myQueue.front()) {
      frontPointer = (frontPointer + 1) % 26;
      forward++;
    }
    while (circularArr[backPointer] != myQueue.front()) {
      backPointer = (backPointer + 26 - 1) % 26;
      backward++;
    }
    minRotation += min(forward, backward);
    myQueue.pop();
  }
  cout << minRotation << endl;
}
