#define DEBUG 0
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define eb emplace_back
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i, begin, end) for(int i = int(begin); i < int(end); i++)
#define UNIQUE(x) sort(all(x)), x.erase(unique(all(x)), x.end())
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>using numr=std::numeric_limits<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll LLINF = 1e16;
const int mod = 1000000007;
const int mod2 = 998244353;
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if DEBUG
#define debug(...)\
    do {\
        std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        std::cerr << std::noboolalpha;\
    } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
    { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
os << "{";
    for (auto it = v.begin(); it != v.end(); it++)
        {os << (it != v.begin() ? "," : "") << *it;}
    return os << "}";
}

// make_v -> auto a = make_v<int>(n,m)
template< typename T = int64_t >
vector< T > make_v(size_t a) {
    return vector< T >(a);
}
template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
    return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}
//ジェネッリックラムダ
template< typename F >
struct FixPoint : F {
    FixPoint(F &&f) : F(forward< F >(f)) {}

    template< typename... Args >
    decltype(auto) operator()(Args &&... args) const {
        return F::operator()(*this, forward< Args >(args)...);
    }
};
template< typename F >
inline decltype(auto) MFP(F &&f) {
    return FixPoint< F >{forward< F >(f)};
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll ans = 0;
    ll a = 11,b=101,c=1001,d=10001,e=100001,f=1000001;
    for(ll i = 1;i<=9;i++){
        ll res = a*i;
        if(n>=res) ans++; 
    }
    for(ll i = 10;i<=99;i++){
        ll res = b*i;
        if(n>=res) ans++; 
    }
    for(ll i = 100;i<=999;i++){ 
        ll res = c*i;
        if(n>=res) ans++; 
    }
    for(ll i = 1000;i<=9999;i++){
        ll res = d*i;
        if(n>=res) ans++; 
    }
    for(ll i = 10000;i<=99999;i++){
        ll res = e*i;
        if(n>=res) ans++; 
    }
    for(ll i = 100000;i<=999999;i++){
        ll res = f*i;
        if(n>=res) ans++; 
    }
    cout << ans << endl; 
}
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
 
int main(){
    ll n; cin >> n;
    for(int i = 1; i <= 1e6; i++){
        int dig = 0;
        ll num = i;
        while(!num==0) {
            num /= 10;
            dig++;
        }
        ll tmp = i + i * pow(10, dig);
        // cout << tmp << endl;
        if (n < tmp) {
            cout << i - 1 << endl;
            return 0;
        }

    }
}