import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

void main() {
    long n;
    scan(n);

    int k;
    while (10L^^(k+1)-1 <= 2*n - 1) k++;

    debug {
        writeln(k);
    }

    long ans;

    foreach (d ; 1 .. 10) {
        long x = d * 10L^^k - 1;
        if (x > 2*n - 1) break;
        auto low = max(1, x - n);
        auto high = min(n + 1, (x + 1) / 2);

        debug {
            writefln("%d, %d", low, high);
        }

        ans += max(0, min(n + 1, high - low));
    }

    writeln(ans);
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}