#include <bits/stdc++.h>
using namespace std;
int main() {
  string s = "abcdefghijklmnopqrstuvwxyz";
  int arr[26] = {0,   1,   2,   3,   4,  5,  6,  7,  8,  9,  10, 11, 12,
                 -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1};
  string x;
  cin >> x;
  int rolls = abs(arr[x[0] - 97]);
  for (int i = 0; i < x.length() - 1; i++) {
    int r = x[i] - 97;
    int l = x[i + 1] - 97;
    rolls += min(abs(arr[l] - arr[r]), abs(26 - abs(arr[l]) - abs(arr[r])));
  }
  cout << rolls;
  return 0;
}
