#include <bits/stdc++.h>
using namespace std;
string s;
int ans = 0;
int abs(int t) {
  if (t < 0)
    return -t;
  else
    return t;
}
int main() {
  cin >> s;
  char p = 'a';
  for (int i = 0; i < s.length(); i++) {
    int t1, t2;
    if (s[i] > p) {
      t1 = s[i] - p;
      t2 = p - 'a' + 1 + 'z' - s[i];
    } else {
      t1 = p - s[i];
      t2 = 'z' - p + s[i] - 'a' + 1;
    }
    p = s[i];
    ans = ans + min(t1, t2);
  }
  cout << ans;
}
