#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> table;
int moveR(int ac, int ax) {
  int ans = 0;
  while (ac != ax) {
    ans++;
    ac = table[ac].first;
  }
  return ans;
}
int moveL(int ac, int ax) {
  int ans = 0;
  while (ac != ax) {
    ans++;
    ac = table[ac].second;
  }
  return ans;
}
int main() {
  string s;
  cin >> s;
  int act = 0;
  table.resize(26);
  for (int i = 1; i < 25; ++i) {
    table[i] = {i + 1, i - 1};
  }
  table[0] = {1, 25};
  table[25] = {0, 24};
  int ans = 0;
  for (char c : s) {
    int ax = c - 'a';
    ans += min(moveR(act, ax), moveL(act, ax));
    act = ax;
  }
  cout << ans << '\n';
  return 0;
}
