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