#O(logN) n = input() if len(n) % 3: ans = int(('9' * ((len(n)) // 3)) if len(n) >= 3 else '0') else: k = len(n) // 3 n1 = int(n[:k]) n2 = int(n[k:2 * k]) n3 = int(n[2 * k:]) if n1 <= n2 and n1 <= n3: ans = n1 else: ans = n1 - 1 print(ans)