def gen_753(l,li=["7","5","3"]):
    if l == 1:
        return li
    new_li = []
    for cand in li:
        new_li.extend([cand + "7",cand + "5",cand + "3"])
    return gen_753(l-1,new_li)

num_str = input()
l = len(num_str)
num = int(num_str)
can_l = [int(num) for num in gen_753(l) if len(set(list(num))) == 3]
count = [i for i in can_l if i <= num]
print(count)