while True:
    try:
        k = int(input())
        ns = []
        while k:
            k, r = divmod(k, 7)
            ns.append(str(r))
        o = ''
        for n in ns:
            o += ['0', '1', '2', '5', '9', '8', '6'][int(n)]
        print(o)
    except Exception as e:
        break

d75438ffc41380356f5b37f4e2620d71a309a688
<mask token>

while True:
    try:
        k = int(input())
        ns = []
        while k:
            k, r = divmod(k, 7)
            ns.append(str(r))
        o = ''
        for n in ns:
            o += ['0', '1', '2', '5', '9', '8', '6'][int(n)]
        print(o)
    except Exception as e:
        break
