import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto n = readln.chomp.to!long, k = (n/(10^^9+1)).to!int; auto s = k.to!string, ns = s.length; auto r = 0; foreach (i; 1..ns) r += 10^^((i+1)/2-1) * 9; auto t = s[0..(ns+1)/2]; r += t.to!int; if (k < chain(s[0..(ns+1)/2], s[0..ns/2].retro).to!int) --r; writeln(r); }