#include using namespace std; int main() { string N; cin >> N; int sz = N.size(); int ans = 0; int st = 1; for( int i = 3; i <= sz; i += 3 ) { int ed = st * 10; if( i < sz ) ans += ed - st; else { long long n = atoll( N.c_str() ); int m = sz / 3; long long l = 1; for( int j = 0; j < m; j++ ) l *= 10; for( long long j = st; j < ed; j++ ) { long long a = j; a += j * l; a += j * l * l; if( a > n ) break; ans++; } } st *= 10; } cout << ans << endl; }