program lunlun_number
  implicit none
  integer :: k, l = 9, i, j, m, n = 9
  integer(8), allocatable :: a(:,:)
  read(*,*) k
  if (k < 10) then
    write(*,'(i0)') k
    stop
  end if
  allocate(a(2,k))
  a = 0_8
  a(1,1:9) = (/1_8, 2_8, 3_8, 4_8, 5_8, 6_8, 7_8, 8_8, 9_8 /)
  do
    do i = 1, 9
      m = 0
      do j = 1, l
        if (mod(a(1,j),10_8) /= 0_8) then
          m = m+1
          a(2,m) = a(1,j)*10_8+mod(a(1,j),10_8)-1_8
          n = n+1
          if (n == k) then
            write(*,'(i0)') a(2,m)
            stop
          end if
        end if
        m = m+1
        a(2,m) = a(1,j)*10_8+mod(a(1,j),10_8)
        n = n+1
        if (n == k) then
          write(*,'(i0)') a(2,m)
          stop
        end if
        if (mod(a(1,j),10_8) /= 9_8) then
          m = m+1
          a(2,m) = a(1,j)*10_8+mod(a(1,j),10_8)+1_8
          n = n+1
          if (n == k) then
            write(*,'(i0)') a(2,m)
            stop
          end if
        end if
      end do
      a(1,1:m) = a(2,1:m)
      l = m
    end do
  end do
end program lunlun_number