#include <bits/stdc++.h>
using namespace std;
void my_ans_is() {
  string s;
  cin >> s;
  long long ct = min(abs('a' - s[0]), 26 - abs(s[0] - 'a'));
  for (long long i = 1; i < s.length(); i++) {
    ct += min(abs(s[i - 1] - s[i]), 26 - abs(s[i - 1] - s[i]));
  }
  cout << ct;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  { my_ans_is(); }
  return 0;
}
