cands = [1, 2, 3, 4, 5, 6, 7, 8, 9]



def add_v(v):

  global cands

  global K

  v = str(v)

  v0 = int(v[-1])

  if v0 == 0:

    cands += [int(v+'0'), int(v+'1')]

    K -=2

  elif v0 == 9:

    cands += [int(v+'8'), int(v+'9')]

    K -= 2

  else:

    cands += [int(v+str(v0-1)), int(v+str(v0)), int(v+str(v0+1))]

    K -= 3



K = int(eval(input()))

idk = K

K -= 9

idx = 0

while K >= 0:

  add_v(cands[idx])

  idx += 1



print((cands[idk-1]))
cands = [1, 2, 3, 4, 5, 6, 7, 8, 9]



def add_v(v):

  global cands

  global K

  v0 = v % 10

  if v0 == 0:

    cands += [v*10, v*10+1]

    K -=2

  elif v0 == 9:

    cands += [v*10+8, v*10+9]

    K -= 2

  else:

    cands += [v*10+v0-1, v*10+v0, v*10+v0+1]

    K -= 3



K = int(eval(input()))

idk = K

K -= 9

idx = 0

while K >= 0:

  add_v(cands[idx])

  idx += 1



print((cands[idk-1]))
cands = [1, 2, 3, 4, 5, 6, 7, 8, 9]


def add_v(v):
    global cands
    global K
    v = str(v)
    v0 = int(v[-1])
    if v0 == 0:
        cands += [int(v + "0"), int(v + "1")]
        K -= 2
    elif v0 == 9:
        cands += [int(v + "8"), int(v + "9")]
        K -= 2
    else:
        cands += [int(v + str(v0 - 1)), int(v + str(v0)), int(v + str(v0 + 1))]
        K -= 3


K = int(eval(input()))
idk = K
K -= 9
idx = 0
while K >= 0:
    add_v(cands[idx])
    idx += 1
print((cands[idk - 1]))

cands = [1, 2, 3, 4, 5, 6, 7, 8, 9]


def add_v(v):
    global cands
    global K
    v0 = v % 10
    if v0 == 0:
        cands += [v * 10, v * 10 + 1]
        K -= 2
    elif v0 == 9:
        cands += [v * 10 + 8, v * 10 + 9]
        K -= 2
    else:
        cands += [v * 10 + v0 - 1, v * 10 + v0, v * 10 + v0 + 1]
        K -= 3


K = int(eval(input()))
idk = K
K -= 9
idx = 0
while K >= 0:
    add_v(cands[idx])
    idx += 1
print((cands[idk - 1]))

-    v = str(v) -    v0 = int(v[-1]) +    v0 = v % 10 -        cands += [int(v + "0"), int(v + "1")] +        cands += [v * 10, v * 10 + 1] -        cands += [int(v + "8"), int(v + "9")] +        cands += [v * 10 + 8, v * 10 + 9] -        cands += [int(v + str(v0 - 1)), int(v + str(v0)), int(v + str(v0 + 1))] +        cands += [v * 10 + v0 - 1, v * 10 + v0, v * 10 + v0 + 1]