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