#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string str;
  cin >> str;
  int sum = 0, pointer = 1, current, t;
  for (int i = 0; i < str.length(); i++) {
    current = (str[i] - 97) + 1;
    if ((pointer - current) < 0)
      t = (26 + pointer) - current;
    else
      t = pointer - current;
    sum += min(t, 26 - t);
    pointer = str[i] - 97 + 1;
  }
  cout << sum;
  return 0;
}
