#include <bits/stdc++.h>
using namespace std;
int main() {
  string s1;
  cin >> s1;
  int sum = 0, a[s1.size() + 1];
  a[0] = 0;
  int k = 1;
  for (int i = 0; i < s1.size(); i++) {
    a[k] = s1[i] - 97;
    k++;
  }
  for (int i = 1; i < s1.size() + 1; i++) {
    int b;
    b = abs(a[i] - a[i - 1]);
    int c = 26 - b;
    sum = sum + min(b, c);
  }
  cout << sum << endl;
  return 0;
}
