#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int sum = 0, final = 0;
  for (int i = 1; i < s.length(); i++) {
    sum = sum + min(abs(s[i] - s[i - 1]), 26 - abs(s[i] - s[i - 1]));
  }
  final = sum + min(abs(s[0] - 'a'), 26 - abs(s[0] - 'a'));
  cout << final;
  return 0;
}
