#include using namespace std; long long n, m = 0; int main() { cin >> n; for (long long i = 1; i < 100000; i++) { long long j = 10, u; while (j <= i) j *= 10; u = i * (1 + j + j * j); if (u <= n) m++; else break; } cout << m << endl; }