#include <bits/stdc++.h>
int main() {
  int i, j, k, l, m, n, o, p, q, count = 0;
  int e[1000] = {0};
  int d[27][2];
  for (i = 1; i <= 26; i++) {
    d[i][0] = i - 1;
    d[i][1] = 27 - i;
  }
  char a[101];
  scanf("%s", a);
  q = strlen(a);
  n = a[0] - 96;
  if (d[n][0] >= d[n][1])
    count += d[n][1];
  else
    count += d[n][0];
  for (i = 1; i < q; i++) {
    m = a[i] - 96;
    k = d[m][0];
    l = d[m][1];
    o = d[n][0];
    p = d[n][1];
    e[0] = k - o;
    e[1] = l - p;
    e[2] = p - l;
    e[3] = o - k;
    e[4] = l + o;
    e[5] = k + p;
    for (j = 0; j <= 5; j++) {
      if (e[j] < 0) e[j] = 1000;
    }
    int min = e[0];
    for (j = 0; j <= 5; j++) {
      if (e[j] <= min) min = e[j];
    }
    count += min;
    n = m;
  }
  printf("%d\n", count);
  return 0;
}
