#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); ll N; cin >> N; ll ans = 0; constexpr ll X = 1e9+1; for(int d = 1; d <= 9; d++) { for(int k = 1; k <= 10; k++) { ll Y = stoll(string(k, char(d + '0'))) * X; if(1 <= Y && Y <= N) ans++; } } cout << ans << endl; }