program abc161d
  use iso_fortran_env
  implicit none
  integer(int64) :: d, i, j, k, p, q, a(100000)
  read *, k
  do i = 1,9
     a(i) = i
  end do
  p = 1
  q = 10
  do while (q <= k)
     do j = -1,1
        d = mod(a(p),10) + j
        if (0 <= d .and. d <= 9) then
           a(q) = 10*a(p) + d
           q = q + 1
        end if
     end do
     p = p + 1
  end do
  print *, a(k)
end program abc161d
