Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
a = list(map(str, list(range(1, 10))))
ans = a + []
illist = []
for i in range(10):
    if i == 0:
        illist.append(["0","1"])
    elif i == 9:
        illist.append(["8","9"])
    else:
        illist.append([str(i-1),str(i),str(i+1)])
while len(ans) < k:
    b = []
    for i in a:
        if i == "323456667":
            break
        intil = int(i[-1])
        c = [i + j for j in illist[intil]]
        b = b + c
    a = b
    ans = ans + b

print(ans[k-1])

Fixed submission:
k = int(input())
from collections import deque
q = deque()
a = list(map(str, list(range(1, 10))))
ans = a + []
illist = []
for i in range(10):
    if i == 0:
        illist.append(["0","1"])
    elif i == 9:
        illist.append(["8","9"])
    else:
        illist.append([str(i-1),str(i),str(i+1)])
for i in range(1,10):
    q.append(str(i))

node = "0"
while node != "323456667":
    node = q.popleft()
    for j in illist[int(node[-1])]:
        nodej = node+j
        q.append(nodej)
        a.append(nodej)

print(a[k - 1])

Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
a = list(map(str, list(range(1, 10))))
ans = a + []
illist = []
for i in range(10):
    if i == 0:
        illist.append(["0","1"])
    elif i == 9:
        illist.append(["8","9"])
    else:
        illist.append([str(i-1),str(i),str(i+1)])
while len(ans) < k:
    b = []
    for i in a:
        if i == "323456667":
            break
        intil = int(i[-1])
        c = [i + j for j in illist[intil]]
        b = b + c
    a = b
    ans = ans + b

print(ans[k-1])

Fixed submission:
k = int(input())
from collections import deque
q = deque()
a = list(map(str, list(range(1, 10))))
ans = a + []
illist = []
for i in range(10):
    if i == 0:
        illist.append(["0","1"])
    elif i == 9:
        illist.append(["8","9"])
    else:
        illist.append([str(i-1),str(i),str(i+1)])
for i in range(1,10):
    q.append(str(i))

node = "0"
while node != "323456667":
    node = q.popleft()
    for j in illist[int(node[-1])]:
        nodej = node+j
        q.append(nodej)
        a.append(nodej)

print(a[k - 1])

Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
a = list(map(str, list(range(1, 10))))
ans = a + []
while len(ans) < k:
    b = []
    for i in a:
        if i == "323456667":
            break
        il = i[-1]
        intil = int(il)
        if il == "0":
            ad = ["0","1"]
        elif il == "9":
            ad = ["8","9"]
        else:
            ad = [intil-1, intil, intil+1]
        c = [i + str(j) for j in ad]
        b = b + c
    a = b
    ans = ans + b

print(ans[k-1])

Fixed submission:
k = int(input())
from collections import deque
q = deque()
a = list(map(str, list(range(1, 10))))
ans = a + []
illist = []
for i in range(10):
    if i == 0:
        illist.append(["0","1"])
    elif i == 9:
        illist.append(["8","9"])
    else:
        illist.append([str(i-1),str(i),str(i+1)])
for i in range(1,10):
    q.append(str(i))

node = "0"
while node != "323456667":
    node = q.popleft()
    for j in illist[int(node[-1])]:
        nodej = node+j
        q.append(nodej)
        a.append(nodej)

print(a[k - 1])

Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
a = list(map(str, list(range(1, 10))))
ans = a + []
while len(ans) < k:
    b = []
    for i in a:
        if i == "323456667":
            break
        il = i[-1]
        intil = int(il)
        if il == "0":
            ad = ["0","1"]
        elif il == "9":
            ad = ["8","9"]
        else:
            ad = [intil-1, intil, intil+1]
        c = [i + str(j) for j in ad]
        b = b + c
    a = b
    ans = ans + b

print(ans[k-1])

Fixed submission:
k = int(input())
from collections import deque
q = deque()
a = list(map(str, list(range(1, 10))))
ans = a + []
illist = []
for i in range(10):
    if i == 0:
        illist.append(["0","1"])
    elif i == 9:
        illist.append(["8","9"])
    else:
        illist.append([str(i-1),str(i),str(i+1)])
for i in range(1,10):
    q.append(str(i))

node = "0"
while node != "323456667":
    node = q.popleft()
    for j in illist[int(node[-1])]:
        nodej = node+j
        q.append(nodej)
        a.append(nodej)

print(a[k - 1])

Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
a = list(map(str, list(range(1, 10))))
ans = a + []
while len(ans) < k:
    b = []
    for i in a:
        inti = int(i)
        if inti > 323456666:
            break
        il = i[-1]
        intil = int(il)
        if intil == 0:
            ad = [0,1]
        elif intil == 9:
            ad = [8,9]
        else:
            ad = [intil-1, intil, intil+1]
        c = [i + str(j) for j in ad]
        b = b + c
    a = b
    ans = ans + b

print(ans[k-1])

Fixed submission:
k = int(input())
from collections import deque
q = deque()
a = list(map(str, list(range(1, 10))))
ans = a + []
illist = []
for i in range(10):
    if i == 0:
        illist.append(["0","1"])
    elif i == 9:
        illist.append(["8","9"])
    else:
        illist.append([str(i-1),str(i),str(i+1)])
for i in range(1,10):
    q.append(str(i))

node = "0"
while node != "323456667":
    node = q.popleft()
    for j in illist[int(node[-1])]:
        nodej = node+j
        q.append(nodej)
        a.append(nodej)

print(a[k - 1])

Buggy python submission (verdict: Time Limit Exceeded):

k = int(input())
a = list(range(1, 10))
ans = a + []
while len(ans) < k:
    b = []
    for i in a:
        if i > 323456666:
            break
        il = str(i)[-1]
        intil = int(il)
        if intil == 0:
            ad = [0,1]
        elif intil == 9:
            ad = [8,9]
        else:
            ad = [intil-1, intil, intil+1]
        c = [int(str(i) + str(j)) for j in ad]
        b = b + c
    a = b
    ans = ans + b

print(ans[k-1])

Fixed submission:
k = int(input())
from collections import deque
q = deque()
a = list(map(str, list(range(1, 10))))
ans = a + []
illist = []
for i in range(10):
    if i == 0:
        illist.append(["0","1"])
    elif i == 9:
        illist.append(["8","9"])
    else:
        illist.append([str(i-1),str(i),str(i+1)])
for i in range(1,10):
    q.append(str(i))

node = "0"
while node != "323456667":
    node = q.popleft()
    for j in illist[int(node[-1])]:
        nodej = node+j
        q.append(nodej)
        a.append(nodej)

print(a[k - 1])