program main
      implicit none
      integer :: k, i, j
      integer(16) :: qu(10000000)

      read *, k
      qu(:) = 0
      j = 0
      do i = 1, 9
        j = j + 1
        qu(j) = i
      end do
      do i = 1, k
        if ( mod(qu(i),10) /= 0 ) then
          j = j + 1
          qu(j) = 10 * qu(i) + mod(qu(i),10) - 1
        end if
        j = j + 1
        qu(j) = 10 * qu(i) + mod(qu(i),10)
        if ( mod(qu(i),10) /= 9 ) then
          j = j + 1
          qu(j) = 10 * qu(i) + mod(qu(i),10) + 1
        end if
      end do
      print *, qu(k)
end program
