#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  int rotation = 0;
  char a = 'a', b;
  for (int i = 0; i < s.size(); i++) {
    b = s[i];
    rotation += min(26 - abs(b - a), abs(b - a) % 26);
    a = s[i];
  }
  cout << rotation;
  return 0;
}
