#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, x, y;
  string s;
  cin >> s;
  x = 'a' - s[0];
  if (x < 0) x = x * -1;
  if ((26 - x) < x) x = 26 - x;
  for (i = 1; i < s.length(); i++) {
    y = s[i] - s[i - 1];
    if (y < 0) y = y * -1;
    if ((26 - y) < y) y = 26 - y;
    x += y;
  }
  cout << x;
  return 0;
}
