program test
implicit none
integer(8) :: k,ans,i,j,list_number(10,0:100000)=0,count=0,count_digit=0,count_digit_before=0,digit=1,tmp=0

read(*,*) k

if(k <= 9) then
  ans = k
else
  
  do i=1,9
    count_digit = count_digit + 1
    count = count + 1
    list_number(digit,count_digit) = i
  enddo
  
  do
    if(list_number(digit,count_digit) == 10**digit - 1) then
      digit = digit + 1
      count_digit_before = count_digit
      count_digit = 0
    endif
    
    do j=1,count_digit_before
      
      tmp = mod(list_number(digit-1,j),10)
      
      if(tmp>=1)then
        count_digit = count_digit + 1
        count = count + 1
        list_number(digit,count_digit) = 10*list_number(digit-1,j) + tmp - 1
        ans = list_number(digit,count_digit)
        if(count == k) then
          goto 100
        endif
        
      endif
      
      count_digit = count_digit + 1
      count = count + 1
      list_number(digit,count_digit) = 10*list_number(digit-1,j) + tmp
      ans = list_number(digit,count_digit)
      if(count == k) then
        goto 100
      endif
      
      if(tmp<=8)then
        count_digit = count_digit + 1
        count = count + 1
        list_number(digit,count_digit) = 10*list_number(digit-1,j) + tmp + 1
        ans = list_number(digit,count_digit)
        if(count == k) then
          goto 100
        endif
        
      endif
      
    enddo
    
  enddo
  
endif

100 continue

write(*,*) ans


end