#include using namespace std; #define int long long #define Rep(i, N) for(int i = 0; i < N; i++) #define AC 1000000001LL signed main() { int N; cin >> N; int ans = 0; for(int i = AC; i <= AC * AC; i = i * 10 + AC) { ans += min(9LL, N / i); } cout << ans << endl; return 0; }