program main
  
  implicit none
  integer :: k
  integer :: i,j,n,m, ans
  integer :: js,je, is, ie
  character(1000000) :: ic
  character(2) :: ic1
  character(3) :: ic2
  character(4) :: ic3
  character(5) :: ic4
  character(6) :: ic5
  
  read(*,*) k
   
  if( k < 10 ) then
    ans = k
  else
    n = 9 
    do i = 10, 100000
      write( ic,* ) i
      if( i < 100 ) then
        js = 1; je = 0
        ic1 = trim( adjustl(ic) )
        do j = je, js
          m = 0
          read(ic1(j:j),*) is
          read(ic1(j+1:j+1),*) ie
          if( abs( is  - ie )   <= 1 ) then
            exit
          else
            m = -1
          end if
        end do
      else if( 100 <= i .and. i < 1000 ) then
        js = 2; je = 0
        ic2 = trim( adjustl(ic) )
        do j = je, js
          m = 0
          read(ic2(j:j),*) is
          read(ic2(j+1:j+1),*) ie
          if( abs( is  - ie )   <= 1 ) then
            exit
          else
            m = -1
          end if
        end do
      else if( 1000 <= i .and. i< 10000 ) then
        js = 3; je = 0
        ic3 = trim( adjustl(ic) )
        do j = je, js
          m = 0
          read(ic3(j:j),*) is
          read(ic3(j+1:j+1),*) ie
          if( abs( is  - ie )   <= 1 ) then
            exit
          else
            m = -1
          end if
        end do
      else if( 10000 <= i .and. i < 100000 ) then
        js = 4; je = 0
        ic4 = trim( adjustl(ic) )
        do j = je, js
          m = 0
          read(ic4(j:j),*) is
          read(ic4(j+1:j+1),*) ie
          if( abs( is  - ie )   <= 1 ) then
            exit
          else
            m = -1
          end if
        end do
      else
        js = 5; je = 0
        ic5 = trim( adjustl(ic) )
        do j = je, js
          m = 0
          read(ic5(j:j),*) is
          read(ic5(j+1:j+1),*) ie
          if( abs( is  - ie )   <= 1 ) then
            exit
          else
            m = -1
          end if
        end do
      end if

      if( m == -1 ) then
      else
        n = n + 1 
      end if
      if( n == k ) then 
        ans = i 
        exit 
      endif
    end do
  endif
   
  print*, ans 

end program main
