#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, q, result = 0;
  string name;
  cin >> name;
  char ch1 = 'a';
  for (size_t i = 0; i < name.size(); i++) {
    result += min(abs(ch1 - name[i]), 26 - abs(ch1 - name[i]));
    ch1 = name[i];
  }
  cout << result;
  return 0;
}
