n = int(input())
name = "665"
cnt = 0

while True:
    name = int(name) +1
    if "666" in str(name):
        cnt += 1
        if n == cnt:
            break
print(name)

48654b5f9fbe4052b385708223078bbed7909288
<mask token>

<mask token>
while True:
    name = int(name) + 1
    if '666' in str(name):
        cnt += 1
        if n == cnt:
            break
print(name)

n = int(input())
name = '665'
cnt = 0
while True:
    name = int(name) + 1
    if '666' in str(name):
        cnt += 1
        if n == cnt:
            break
print(name)

n = int(input())
name = "665"
cnt = 0

while True:
    name = int(name) +1
    if "666" in str(name):
        cnt += 1
        if n == cnt:
            break
print(name)
