#include <bits/stdc++.h>
using namespace std;
int main() {
  char ch[10000];
  while (cin >> ch) {
    int len = strlen(ch);
    int num = 0;
    int sum = 0;
    for (int i = 0; i < len; i++) {
      int u = (ch[i] - 'a' - num + 26) % 26;
      int us = (num - (ch[i] - 'a') + 26) % 26;
      int p = min(u, us);
      sum += p;
      num = ch[i] - 'a';
    }
    cout << sum << endl;
  }
  return 0;
}
