#include <bits/stdc++.h>
using namespace std;
int main(void) {
  string s;
  cin >> s;
  int rots{};
  int prev = 'a';
  for (char c : s) {
    rots += min(abs(c - prev), 26 - abs(c - prev));
    prev = c;
  }
  cout << rots << endl;
  return 0;
}
