def solve(s: str): digits = [int(c) for c in s] lt = False # less than st = [] for d in digits: if lt: st.append(5) continue if d > 5: lt = True st.append(5) elif d >= 4: st.append(d) else: n = len(st) while st and st[-1] == 4: st.pop() if len(st) == 0: st = [5] * n lt = True else: # 最も右側の 5 を 4 に変更 assert st[-1] == 5 st.pop() st.append(4) st.extend([5] * (n - len(st) + 1)) lt = True return st N = input() ans = solve(N) print(*ans, sep='')