https://www.acmicpc.net/problem/1526
n=input() while 1: c=0 for i in range(len(n)): if n[i]!='4' and n[i]!='7': c=1 break if c==0: break else: n=str(int(n)-1) print(n)