#include #include using namespace std; typedef long long ll; int main() { ll n; cin >> n; ll num = 1e9 + 1; if(n < num) { cout << 0 << endl; return 0; } else { ll a = n / num; ll ans = 0; ll ma = 9; int cnt=0; int p = 1; while(a > 0) { cnt++; if(cnt%2) p *= 9; ma = min(ma, a%10); a /= 10; ans += p; cnt++; } ans -= p; ans += ma; cout << ans << endl; } }