program abc161d
  use iso_fortran_env
  implicit none
  integer :: k, d, i, j, h, t
  integer(int64) :: ans, a(300000)
  read *, k
  do i = 1,9
     a(i) = i
  end do
  h = 1
  t = 10
  do i = 1,k
     ans = a(h)
     h = h + 1
     do j = -1,1
        d = mod(ans,10)
        d = d + j
        if (d >= 0 .and. d <= 9) then
           a(t) = ans * 10 + d
           t = t + 1
        end if
     end do
  end do
  print *, ans
end program abc161d
