K = int(eval(input()))

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



if K <= 9:

  print(K)

  exit()



cnt = 9

while cnt < K:

  _ = d.pop(0)

  matsubi = _%10

  

  if matsubi == 0:

    d.append(_*10+matsubi)

    cnt += 1

    if cnt == K:

      print((d[-1]))

      exit()

    d.append(_*10+matsubi+1)

    cnt += 1

    if cnt == K:

      print((d[-1]))

      exit()

    

  elif matsubi == 9:

    d.append(_*10+matsubi-1)

    cnt += 1

    if cnt == K:

      print((d[-1]))

      exit()



    d.append(_*10+matsubi)

    cnt += 1

    if cnt == K:

      print((d[-1]))

      exit()

  else:

    d.append(_*10+matsubi-1)

    cnt += 1

    if cnt == K:

      print((d[-1]))

      exit()



    d.append(_*10+matsubi)

    cnt += 1

    if cnt == K:

      print((d[-1]))

      exit()



    d.append(_*10+matsubi+1)

    cnt += 1

    if cnt == K:

      print((d[-1]))

      exit()
K = int(eval(input()))

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



if K <= 9:

  print(K)

  exit()



cnt = 9

while cnt < K:

  _ = d.pop(0)

  matsubi = _%10

  

  if matsubi == 0:

    d.append(_*10+matsubi)

    d.append(_*10+matsubi+1)

    cnt += 2



  elif matsubi == 9:

    d.append(_*10+matsubi-1)

    d.append(_*10+matsubi)

    cnt += 2



  else:

    d.append(_*10+matsubi-1)

    d.append(_*10+matsubi)

    d.append(_*10+matsubi+1)

    cnt += 3

      

ans = -1*(cnt - K + 1)

print((d[ans]))
K = int(eval(input()))
d = [1, 2, 3, 4, 5, 6, 7, 8, 9]
if K <= 9:
    print(K)
    exit()
cnt = 9
while cnt < K:
    _ = d.pop(0)
    matsubi = _ % 10
    if matsubi == 0:
        d.append(_ * 10 + matsubi)
        cnt += 1
        if cnt == K:
            print((d[-1]))
            exit()
        d.append(_ * 10 + matsubi + 1)
        cnt += 1
        if cnt == K:
            print((d[-1]))
            exit()
    elif matsubi == 9:
        d.append(_ * 10 + matsubi - 1)
        cnt += 1
        if cnt == K:
            print((d[-1]))
            exit()
        d.append(_ * 10 + matsubi)
        cnt += 1
        if cnt == K:
            print((d[-1]))
            exit()
    else:
        d.append(_ * 10 + matsubi - 1)
        cnt += 1
        if cnt == K:
            print((d[-1]))
            exit()
        d.append(_ * 10 + matsubi)
        cnt += 1
        if cnt == K:
            print((d[-1]))
            exit()
        d.append(_ * 10 + matsubi + 1)
        cnt += 1
        if cnt == K:
            print((d[-1]))
            exit()

K = int(eval(input()))
d = [1, 2, 3, 4, 5, 6, 7, 8, 9]
if K <= 9:
    print(K)
    exit()
cnt = 9
while cnt < K:
    _ = d.pop(0)
    matsubi = _ % 10
    if matsubi == 0:
        d.append(_ * 10 + matsubi)
        d.append(_ * 10 + matsubi + 1)
        cnt += 2
    elif matsubi == 9:
        d.append(_ * 10 + matsubi - 1)
        d.append(_ * 10 + matsubi)
        cnt += 2
    else:
        d.append(_ * 10 + matsubi - 1)
        d.append(_ * 10 + matsubi)
        d.append(_ * 10 + matsubi + 1)
        cnt += 3
ans = -1 * (cnt - K + 1)
print((d[ans]))

-        cnt += 1 -        if cnt == K: -            print((d[-1])) -            exit() -        cnt += 1 -        if cnt == K: -            print((d[-1])) -            exit() +        cnt += 2 -        cnt += 1 -        if cnt == K: -            print((d[-1])) -            exit() -        cnt += 1 -        if cnt == K: -            print((d[-1])) -            exit() +        cnt += 2 -        cnt += 1 -        if cnt == K: -            print((d[-1])) -            exit() -        cnt += 1 -        if cnt == K: -            print((d[-1])) -            exit() -        cnt += 1 -        if cnt == K: -            print((d[-1])) -            exit() +        cnt += 3 +ans = -1 * (cnt - K + 1) +print((d[ans]))