N = input() d = len(N) ret = [-1] * d now = 0 while now < d and N[now] in "45": now += 1 if now == d: print(N) exit() if now == 0: if N[now] in "6789": print("5" * d) exit() else: print("5" * (d - 1)) exit() if N[now] in "6789": rest = False else: rest = True for i in range(now, d): ret[i] = "5" while now > 0: now -= 1 if rest: if N[now] == "5": ret[now] = "4" rest = False elif now > 0: ret[now] = "5" else: ret[now] = N[now] print("".join(ret))