#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int minRots = 0;
  char curr = 'a';
  for (char x : s) {
    int clock, anti;
    if (x > curr) {
      clock = x - curr;
      anti = (curr - 'a') + ('z' - x) + 1;
    } else {
      clock = ('z' - curr) + (x - 'a') + 1;
      anti = curr - x;
    }
    minRots += min(clock, anti);
    clock = anti = 0;
    curr = x;
  }
  cout << minRots << '\n';
}
