using System; public class Hello { static void Main() { var s = Console.ReadLine().Trim(); getAns(s); } static void getAns(string s) { var n = s.Length; if (n % 3 != 0) { var w = n / 3; Console.WriteLine(w > 0 ? new string('9', w) : "0"); } else { var w = n / 3; var ws = s.Substring(0, w); var ww = int.Parse(ws); var www = long.Parse(ws + ws + ws); var ww2 = w > 1 ? int.Parse(new string('9', w - 1)) : 0; var ans = ww + ww2; if (www > long.Parse(s)) ans--; Console.WriteLine(ans); } } }