#include <cstdio>
#include <iostream>
#include <algorithm>
long long B = 10;
using namespace std;

long long exponent(long long r, long long base) {
    long long sum = 1;
    for (int i = 1; i <= r; i++) {
        sum *= base;
    }
    return sum;
}

int main() {

    long long N;
    scanf("%lld", &N);
    int digits = 0;
    long long temp_N = N;
    while (temp_N) {
        temp_N /= B;
        digits++;
    }
    if ((digits & 1) == 1){
        int half = (digits - 1) / 2;

        long long sum = 0;
        long long base = 1;
        for(int i = 0;i <= half - 1;i++){
            sum += base * 9;
            base *= 10;
        }
        printf("%lld", sum);
    }
    else{
        long long base = exponent(digits / 2, 10);
        long long high = N / base;
        long long sum = high;
        if (high * base + high > N) sum -= 1;
        printf("%lld", sum);

    }

}


#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <iterator>
#include <stack>
#include <queue>
#include <functional>
#include <map>
using namespace std;

#define ll long long
#define double long double
#define vi vector<int>
#define vvi vector<vi>
#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>

int main()
{
    string N;
    cin >> N;
    string front, back;
    int half_size = N.size() / 2;
    if (half_size == 0)
    {
        cout << "0" << endl;
        return 0;
    }

    if (N.size() % 2 == 0)
    {
        for (size_t i = 0; i < half_size; i++)
        {
            front += N[i];
            back += N[half_size + i];
        }
    }
    else
    {
        for (size_t i = 0; i < half_size; i++)
        {
            front += "9";
            back += "9";
        }
    }

    int front_int, back_int;
    front_int = stoi(front);
    back_int = stoi(back);
    int ans = 0;
    if (front_int <= back_int)
    {
        ans++;
    }
    front_int--;
    ans += front_int;
    cout << ans << endl;

    return 0;
}
