# https://www.acmicpc.net/problem/1436

def answer(n):
    i = 666
    l = []
    while True:
        if '666' in str(i):
            l.append(i)
        i += 1
        if len(l) >= n:
            break
    return l[n - 1]


n = int(input())
print(answer(n))
9026287021bef63ac75b51de3b86429ce0fe338c
<mask token>

def answer(n):
    i = 666
    l = []
    while True:
        if '666' in str(i):
            l.append(i)
        i += 1
        if len(l) >= n:
            break
    return l[n - 1]


<mask token>

def answer(n):
    i = 666
    l = []
    while True:
        if '666' in str(i):
            l.append(i)
        i += 1
        if len(l) >= n:
            break
    return l[n - 1]


<mask token>
print(answer(n))

def answer(n):
    i = 666
    l = []
    while True:
        if '666' in str(i):
            l.append(i)
        i += 1
        if len(l) >= n:
            break
    return l[n - 1]


n = int(input())
print(answer(n))

# https://www.acmicpc.net/problem/1436

def answer(n):
    i = 666
    l = []
    while True:
        if '666' in str(i):
            l.append(i)
        i += 1
        if len(l) >= n:
            break
    return l[n - 1]


n = int(input())
print(answer(n))