#include <bits/stdc++.h>
using namespace std;
vector<int> V, B;
int n, x, a, b, c, cnt = 1, ans, l, r, m;
string s;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    x = s[i] - 96;
    a = abs(x - cnt);
    b = 26 - a;
    ans += min(a, b);
    cnt = x;
  }
  cout << ans;
}
