#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int a = 'a', z = 'z', min_rotations = 0, cost1, cost2;
  char curr = 'a', big, small;
  for (int i = 0; i < s.size(); i++) {
    big = max(curr, s[i]);
    small = min(curr, s[i]);
    cost1 = big - small;
    cost2 = (small - a) + (z - big) + 1;
    min_rotations += min(cost1, cost2);
    curr = s[i];
  }
  cout << min_rotations << endl;
  return 0;
}
