#include <bits/stdc++.h>
using namespace std;
int main() {
  char s[110];
  int i, j, n, fir, sec, r1, r2, r, sum = 0, m, m1;
  cin >> s;
  n = strlen(s);
  m = s[0] - 'a';
  m1 = 25 - m + 1;
  if (m > m1) m = m1;
  for (i = 0; i < (n - 1); i++) {
    fir = s[i] - 'a';
    sec = s[i + 1] - 'a';
    r1 = sec - fir;
    if (r1 > 0) {
      r2 = 25 - sec + 1 + fir;
    } else if (r1 < 0) {
      r2 = 25 - fir + 1 + sec;
      r1 *= (-1);
    } else
      r2 = 0;
    if (r1 < r2)
      r = r1;
    else
      r = r2;
    sum += r;
  }
  sum += m;
  cout << sum << endl;
  return 0;
}
