#include #define rep(i,n)for(int i=0;i<(n);i++) using namespace std; typedef long long ll; typedef pairP; int main() { ll a = 1e9 + 1; ll n; cin >> n; int cnt = 0; for (int i = 1; i < 100; i++) { for (int j = 1; j <= 9; j++) { string s; rep(k, i)s += j + '0'; ll b = stoll(s); if (n / a < b)goto g; else cnt++; } } g:; cout << cnt << endl; }