#include <bits/stdc++.h>
int main() {
  int current_index = 97, next_index = 0, tmp1 = 0, tmp2 = 0, count = 0;
  std::string s = "";
  std::cin >> s;
  for (int i = 0; i < s.length(); i++) {
    next_index = (int)s.at(i);
    if (current_index <= 109) {
      if (next_index - current_index < 0)
        tmp1 = (next_index - current_index) * -1;
      else
        tmp1 = next_index - current_index;
      tmp2 = current_index - 97 + 122 - next_index + 1;
      if (tmp1 > tmp2)
        count += tmp2;
      else
        count += tmp1;
      current_index = next_index;
    } else {
      if (next_index - current_index < 0)
        tmp1 = (next_index - current_index) * -1;
      else
        tmp1 = next_index - current_index;
      tmp2 = 122 - current_index + next_index - 97 + 1;
      if (tmp1 > tmp2)
        count += tmp2;
      else
        count += tmp1;
      current_index = next_index;
    }
  }
  std::cout << count;
  return 0;
}
