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