#include <bits/stdc++.h>
using namespace std;
string str;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> str;
  char current = 'a';
  long long sum = 0;
  for (int i = 0; i < str.size(); ++i) {
    int _1 = current - str.at(i);
    int _2 = str.at(i) - current;
    if (_2 < 0)
      _2 += 26;
    else
      _1 += 26;
    sum += min(_1, _2);
    current = str.at(i);
  }
  cout << sum << endl;
  return 0;
}
