#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  int ans = 0, i = 0;
  for (char c : s) {
    int curr = c - 'a';
    ans += min(abs(curr - i), 26 - (abs(i - curr)));
    i = curr;
  }
  cout << ans << "\n";
  return 0;
}
