#include <bits/stdc++.h>
int pos(int a) { return (a > 0) ? a : -a; }
int min(int a, int b) { return (a > b) ? b : a; }
int main() {
  char c;
  int total = 0;
  char prev = 'a';
  while (c = getchar()) {
    if (c == '\n') break;
    int d = min(pos(c - prev + 26), min(pos(prev - c + 26), pos(c - prev)));
    prev = c;
    total += d;
  }
  printf("%d\n", total);
  return 0;
}
