#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
char s[maxn];
int ans = 0;
int a[27][27];
int main() {
  scanf("%s", s);
  int len = strlen(s);
  for (int i = 1; i <= 26; ++i) {
    for (int j = 1; j <= 26; ++j) {
      a[i][j] = min(abs(i - j), min(abs(26 - i + j), abs(26 - j + i)));
    }
  }
  for (int i = 1; i < len; ++i) {
    ans += a[s[i] - 'a' + 1][s[i - 1] - 'a' + 1];
  }
  ans += a[1][s[0] - 'a' + 1];
  printf("%d\n", ans);
  return 0;
}
