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