USA

#include <bits/stdc++.h
using namespace std;
using ll = long long;
/*
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%@@@@@@@@@@@@@%@#########%@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@@@@@@@@%########@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@%%@@@@@@@@%%######@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%%%%%###%%@@@@@%*#%#@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@#@@@@@@@@@@@@@@@@@@@@@@@@@@@@%%+=-----===+*##%@%###@@@@@@@@@@@@@@@@@@@@@ %@@@@@@@@@*@@@@@@@@@@@@@@@@@@@@@@@@@%=--::::------=+*##@%%#@@@@@@@@@@@@@@@@@@@@@ %@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%=--::--------==+**##@%#@@@@@@@@@@@@@@@@@@@@@ @%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*---::::::::--+===+#*#@#@@@@@@@@@@@@@@@@@@@@@ %%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%+--::---:::++-:--+=+**%#@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@=--::-=-:-=*#++**+#=*###@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*-:-:::----+#***+=++*#*+%@@@@@@@@@@@%%@@@@@@@ @@@@@@%@@@@@@@@@@@@@@@@@@@@@@@@@@@@%=--:--:-::--=+--=++*##*+%%%@@@@@@@@@%%@@@@@@ @@@@@#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@-=-:::::--::=+==--=+*#*+#@@@@@@@@@@@@@@*@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@=:--::::-::--=-====+**+*@@@@@@@@@@@@@@@@:@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@-=-:::-----------+++*##@@@@@@@@@@@@@@@@@%@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@=--::::::--:----++*###@@@@@@@@@@@@@@@@@@%@% @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@=----::::::--=++#*##*@@@@@@@@@@@@@@@@@@%#* @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#++==---===+*****##*@%%%@@@@@@@@@@@@@@@#% @@@@@@@@@@@@@@@@@@*:-#@@+::::::*@@@@@@@@++========++**+*##*@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@::-@@...:::::::+%#@@@+++===---=+++==+*##@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@::-=....:::::::::-*#@++++++=-++++====+%*@@@@@@@@@%@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@::::....:::::::::=#+%*++++++++++==--==**%+@@@@@@%@@@@@@@@@@@@ @%@@@@@@@@@@@@@@@@@:........:::::::-*%%@***++++++++==---=+*@+@#%%%%@@@@@@@@@@@%% @@@@@@@@@@@@@@@@@@@@%:......:::::--+@@@@+@#*++++++++===-#%-+@###%@%#%%%@@@@@@@%% @@@@@@@@@@@@@@@@@@@@@@:..-*::+-:-=+%*=*%@@+*%@%++++*%%@:--%+.-%%@@%###%%%%%@@@#% @@@@@@@%#@@@@@@@@@@@@@*-+=:.-:.#=+%-%@@#**@@@@%+=--::%%%%:.*=%%%=@%##%##%%%%%%%% @@@@@@@@@@@@@@@@@@@@%@#-=-:.--%%%%%@=*#%*=@@+@+%-=%:%%:@%%-*.%%%%%=+..:::%%%#%%% @@@@@@@@@@@@@@#@@@@%#@#....-::-++@%-*+@@@@*@#=@@%%%#%*#-%%%%%%+-.%%%%%%--.=.-@%% @@@@@@@@@@@@@@@#@@@#*#:.....::-=*%%%@@**=@@@@@%*+#%*+++*%.==%.@...%%#%%%###%%=%% @@@@@@@@@@@@@@@@@@@*#%:....::::=%%*=%#%===@@%#@#-:**+=*+*%:. %%%%%#-=+%%%%%%:%:* @@@@@@@@@@@@%%%%@@@@*#:....:::-+%%-@%@@@@@#***+%%%%*+===+*#%%::+-%:%...%%%%+-=.: @@@@@@@@@@@@@@%%@@%%@::...::::-*%%%@%+%@#%@#*-%+:%%*+++==+#%%%*=-.%%%%%=:=%#%%%% @@@@@@@%@@@@@@@@@@%*%:.....:::=#%%*@%%=*%%#@@%.%+*%+#++===+#==%%%%-.@:%+.. @#%%+ @@@@@@@@%@@@@@@@@@%*-:......:-+@%*#*@@@@@%*-+=%%=+%#*+==-=++==%+%%%@#-%%%%%-#%#: @@@%@@@@@@@@@@@@-@@*:......::-*%==*@@@+@%%+=:#*%%+:#*++---++-+%=-%%%%%+#*%%@#%%% @@@%%@@@@@@@@@@@@@@-:......:--*@@@@@@***@%%%++*++.*+*-++--*+*##:#:*%%%*.*%@##%*% @@@@@@%%#%%@@@@@+@*:...::.::-=*@*+%@#*=*-%%*%%%-=+*+#+++-=*-+#=--=::-@@%%@#%%*+: @@@@@@@@@@@@@@@@+%-:..::.:::-=*=@##%@@@@@%#*-%%+*+===*+=*===::---#+-*@+%%-%%#+%% @@@@@@@@@@@@@#%@@-::::::::::-=*@@@%%##=%@+..##-#=++=--*#+*--+=+#%%%%%#*=%%%*==%@ @@@@@@@@@@@@@%%%-:::::.::::--+*@@@@@+%#**+=----=#+*+=*+*#+==++*%%@#%@*=@%@%-.-%@
*/
ll closest_even(ll a) { //переименуй
string s = to_string(a);
int n = s.size();
for (int i = 0; i < n; i++) {
int d = s[i] - '0';
if (d % 2 == 1) {
s[i]--;
for (int j = i + 1; j < n; j++) {
s[j] = '8';
}
break;
}
}
return stoll(s);
}
int main() {
ll n; //ll = int
cin >> n;
ll cnt = 0;
while (n > 0) {
ll x = closest_even(n);
cnt += (n - x);
n = x;
if (n > 0) {
n /= 2;
cnt++;
}
}
cout << cnt;
}
