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