#include <bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(false);cin.tie(0);
#define setnow clock_t tStart=clock();
#define time (double)(clock() - tStart)/CLOCKS_PER_SEC;
#define setin(x) ifstream cin(x);
#define setout(x) ofstream cout(x);
typedef long long ll;
typedef long long int lli;
typedef pair < int, int> dbl;
const int maxInt = 1e9*2;
const lli maxLong = 1e18*2;
map <char, pair<int, int> > mp;
char arr[3][10] = {
	{'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P'},
	{'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ' ' },
	{ 'Z', 'X', 'C', 'V', 'B', 'N', 'M', ' ', ' ', ' ' }
}; 

int distance(int a, int b, int c, int d){
	return( abs(a-c) + abs(b-d) );
}
int main(){
	
	for(char l='A'; l<='Z'; l++){
		for(int i=0;i<3;i++){
			for(int j=0;j<10;j++){
				
				if(arr[i][j] == l){
				    mp[l].first = i+1;
		            mp[l].second = j+1; 
				}
			}
		}
	}
	int ans = 0;
	string str;
	cin >> str;
	char left = 'F';
	char right = 'J';
	//cout << mp['A'].first << ' ' << mp['A'].second << endl;
	for(unsigned i=0;i<str.size();i++){
		
		
		int distL = distance(mp[left].first, mp[left].second, mp[str[i]].first, mp[str[i]].second);
		int distR = distance(mp[right].first, mp[right].second, mp[str[i]].first, mp[str[i]].second);
		if(distL < distR){
			ans+=distL;
			//cout << left << ' ' << str[i] << endl;
			//cout << mp[left].first << ' ' << mp[left].second;
			//cout << mp[str[i]].first << ' ' << mp[str[i]].second;
			//cout<<"LEFT"<<' '<<distL<<endl;
			left = str[i];
		}else{
			ans+=distR;
			//cout << distR<<endl;
			right = str[i];
		}
	}
	cout<<ans;
}