#include <bits/stdc++.h>
const int mod = 1000000007;
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  string s;
  cin >> s;
  int current = 1;
  int pos, d, k;
  int sum = 0;
  for (int i = 0; i < s.length(); i++) {
    pos = s[i] - 'a' + 1;
    d = abs(pos - current);
    k = (d < 26 - d ? d : 26 - d);
    sum = sum + k;
    current = pos;
  }
  cout << sum << "\n";
  ;
}
