#include using namespace std; int main(void) { cin.tie(0); ios::sync_with_stdio(false); long long int N; cin >> N; long long int cnt = 0; __int128 base = 0; for(int i=0;i<9;i++) { base += pow(10,i); //cout << i << ' ' << base << '\n'; for(long long int j=1;j<10;j++) { __int128 val = base*j; val += (j*base*1000000000LL); if(val<=N) { long long int temp = val; //cout << temp << '\n'; cnt++; } } } cout << cnt << '\n'; return 0; }