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