#include <bits/stdc++.h>
using namespace std;
const char array_sep[] = " ";
const char array_end[] = "";
const char pair_sep[] = " ";
const char pair_end[] = "";
const char map_sep[] = "->";
const char map_end[] = "\n";
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
const int ddx[] = {-1, -1, 0, 1, 1, 1, 0, -1};
const int ddy[] = {0, 1, 1, 1, 0, -1, -1, -1};
template <typename A>
ostream& operator<<(ostream& os, const vector<A>& x) {
  for (int i = 0; i < x.size(); i++) os << x[i] << array_sep;
  os << array_end;
  return os;
}
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
  os << x.first << pair_sep << x.second << pair_end;
  return os;
}
template <typename A>
istream& operator>>(istream& is, vector<A>& x) {
  for (int i = 0; i < x.size(); i++) is >> x[i];
  return is;
}
template <typename A, typename B>
istream& operator>>(istream& is, pair<A, B>& x) {
  is >> x.first >> x.second;
  return is;
}
template <typename _response>
void die(_response ans) {
  cout << ans << endl;
  exit(0);
}
int main() {
  ios_base::sync_with_stdio(0);
  string s;
  cin >> s;
  int ans = 0;
  int cur = 0 + 1;
  for (auto& c : s) {
    int b = c - 'a' + 1;
    ans += min(min(abs(b - cur), cur + 26 - b), 26 - cur + b);
    if (false)
      cerr << min(min(abs(b - cur), cur + 26 - b), 26 - cur + b) << endl;
    cur = b;
  }
  cout << ans << endl;
  return 0;
}
