S = input() N = len(S) if S < "4"*N: exit(print("5"*(N-1))) ans = [-1]*N small = False idx = -1 for i in range(N): if not small: if 4 == int(S[i]): ans[i] = 4 elif 5 == int(S[i]): ans[i] = 5 elif 5 < int(S[i]): ans[i] = 5 small = True else: ans[i] = 5 idx = i small = True else: ans[i] = 5 if idx != -1: for i in reversed(range(idx)): if S[i] == "5": ans[i] = 4 break print("".join(map(str, ans)))