#include <bits/stdc++.h>
using namespace std;
int main() {
  string str;
  for (int i = 'a'; i <= 'z'; i++) str += i;
  string given_str;
  int current_cursor_pos = 1;
  int res = 0;
  int given_character_pos;
  getline(cin, given_str);
  int temp1, temp2;
  for (int i = 0; i < given_str.length(); i++) {
    given_character_pos = int(given_str[i]) - 96;
    temp1 = 26 - abs(given_character_pos - current_cursor_pos);
    temp2 = abs(current_cursor_pos - given_character_pos);
    if (temp1 < temp2) {
      res += temp1;
    } else {
      res += temp2;
    }
    current_cursor_pos = given_character_pos;
  }
  cout << res;
  return 0;
}
