#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<vector<int>> dp(200, vector<int>(200, 0));
  for (char i = 'a'; i <= 'z'; i++)
    for (char j = 'a'; j <= 'z'; j++) {
      if (i <= j)
        dp[i][j] = min(i + 26 - j, j - i);
      else
        dp[i][j] = min(i - j, j + 26 - i);
    }
  string s;
  cin >> s;
  int ans = 0;
  ans += dp['a'][s[0]];
  for (int i = 0; i < s.size() - 1; i++) ans += dp[s[i]][s[i + 1]];
  cout << ans;
}
