#include #include #include #include #include #include #include #include #include #include using ll = long long; using namespace std; int main() { string n; ll ans = 0; cin >> n; if (n.size() < 3) cout << 0 << "\n"; else if (n.size() >= 3 && (n.size()%3)){ ans = pow(10, n.size()/3) - 1; cout << ans << endl; } else { string a, b, c; ans = pow(10, n.size()/3 - 1) - 1; a = n.substr(0, n.size()/3); b = n.substr(n.size()/3, n.size()/3); c = n.substr(n.size()*2/3, n.size()/3); if (stoll(a) != (ans+1)) ans += (stoll(a) - 1); if (stoll(a) < stoll(b)) ans++; else if ((stoll(a) == stoll(b)) && (stoll(a) <= stoll(c)))ans++; cout << ans << endl; } }