#include <bits/stdc++.h>
using namespace std;
const int inf = (int)(1e9) + 100;
const int mod = (int)(1e9) + 100;
const int N = (int)(2e5) + 100;
string s;
char a[30], c = 'a';
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> s;
  for (int i = 1; i <= 26; i++) a[i] = c++;
  int cur = 1;
  int ans = 0;
  for (int i = 0; i < s.size(); i++) {
    if (a[cur] == s[i])
      continue;
    else {
      if (s[i] > a[cur]) {
        int r = s[i] - a[cur];
        int l = a[cur] - 'a' + 'z' - s[i] + 1;
        ans += min(l, r);
        cur = int(s[i] - 'a') + 1;
      } else {
        int r = a[cur] - s[i];
        int l = s[i] - 'a' + 'z' - a[cur] + 1;
        ans += min(l, r);
        cur = int(s[i] - 'a') + 1;
      }
    }
  }
  cout << ans;
  return 0;
}
