#include <bits/stdc++.h>
using namespace std;
int xp[130], yp[130];
void init(){
for (int i = 'A'; i <= 'Z'; i ++){
xp[i] = i / 6 + 1;
yp[i] = i % 6 + 1;
}
xp[' '] = 5, yp[' '] = 3;
xp['-'] = 5, yp['-'] = 4;
xp['.'] = 5, yp['.'] = 5;
}
int main(){
init();
string s;
getline(cin, s);
char bef = 'A';
int ans = 0;
for (char i : s){
ans += abs(xp[i] - xp[bef]) + abs(yp[i] - yp[bef]);
}
ans += abs(5 - xp[bef]) + abs(6 - yp[bef]);
cout << ans;
}