n = int(input())
for i in range(1, n + 1):
    num_str = str(i) # 遍历每个数字转化为字符类型后用in判断是否有4
    if '4' not in num_str and i % 4 != 0:
        print(i)