K = int(input())
l = [0]*(10**5+10)
l[1:10] = list(range(1,10))
keta = 2
i=10
def res(now):
    if int(now[-1])==0:
      for a in range(0,2):
        ret=str(now)+str(a)
        yield ret
    elif int(now[-1])==9:
      for a in range(8,10):
        ret=str(now)+str(a)
        yield ret
    else:
      for a in range(int(now[-1])-1,int(now[-1])+2):
        ret=str(now)+str(a)
        yield ret
        
while i!=10**5+1:
  if keta==1:
    keta+=1
    l[i]=i
    i+=1
  elif keta==2:
    for j in range(1,10):
      for k in res(str(j)):
        l[i]=k
        i+=1
    keta+=1
  elif keta==3:
    for j in range(1,10):
      for k in res(str(j)):
        for a in res(str(k)):
          l[i]=a
          i+=1
    keta+=1
  elif keta==4:
    for j in range(1,10):
      for k in res(str(j)):
        for a in res(str(k)):
          for b in res(str(a)):
            l[i]=b
            i+=1
    keta+=1
  elif keta==5:
    for j in range(1,10):
      for k in res(str(j)):
        for a in res(str(k)):
          for b in res(str(a)):
            for c in res(str(b)):
              l[i]=c
              i+=1
    keta+=1
  elif keta==6:
    for j in range(1,10):
      for k in res(str(j)):
        for a in res(str(k)):
          for b in res(str(a)):
            for c in res(str(b)):
              for d in res(str(c)):
                l[i]=d
                i+=1
    keta+=1
  elif keta==7:
    for j in range(1,10):
      for k in res(str(j)):
        for a in res(str(k)):
          for b in res(str(a)):
            for c in res(str(b)):
              for d in res(str(c)):
                for e in res(str(d)):
                  l[i]=e
                  i+=1
    keta+=1
  elif keta==8:
    for j in range(1,10):
      for k in res(str(j)):
        for a in res(str(k)):
          for b in res(str(a)):
            for c in res(str(b)):
              for d in res(str(c)):
                for e in res(str(d)):
                  for f in res(str(e)):
                    l[i]=f
                    i+=1
    keta+=1
  elif keta==9:
    for j in range(1,10):
      for k in res(str(j)):
        for a in res(str(k)):
          for b in res(str(a)):
            for c in res(str(b)):
              for d in res(str(c)):
                for e in res(str(d)):
                  for f in res(str(e)):
                    for g in res(str(f)):
                      l[i]=g
                      i+=1
    keta+=1
  elif keta==10:
    for j in range(1,10):
      for k in res(str(j)):
        for a in res(str(k)):
          for b in res(str(a)):
            for c in res(str(b)):
              for d in res(str(c)):
                for e in res(str(d)):
                  for f in res(str(e)):
                    for g in res(str(f)):
                      for h in res(str(g)):
                        l[i]=h
                        i+=1
                        if i==10**5+5:
                          break
                      else:
                        continue
                      break
                    else:
                      continue
                    break
                  else:
                    continue
                  break
                else:
                  continue
                break
              else:
                continue
              break
            else:
              continue
            break
          else:
            continue
          break
        else:
          continue
        break
      else:
        continue
      break
    else:
      continue
    break
    
print(int(l[K]))

Measured memory_bytes: 10096