#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
  int s[26];
  char ch[101];
  for (int i = 'a', j = 0; i <= 'z'; i++, j++) {
    s[i] = j;
  }
  int cnt = 0;
  cin.getline(ch, sizeof(ch));
  char d = 'a';
  for (int i = 0; i < strlen(ch); i++) {
    cnt += min(abs(s[ch[i]] - s[d]), 26 - abs(s[ch[i]] - s[d]));
    d = ch[i];
  }
  cout << cnt;
  return 0;
}
