   program abc161d
      implicit none
!参考有
      integer::k
      integer::i,j,m,n
      integer::Kazu(10,0:9),Sowa(0:10)
      integer::check  !check;counter

         read *,k

         Kazu(1,:)=1
         do i=2,10
            do j=0,9
               if (j==0) then
                  Kazu(i,j)=Kazu(i-1,j)+Kazu(i-1,j+1)
               else if (j==9) then
                  Kazu(i,j)=Kazu(i-1,j-1)+Kazu(i-1,j)
               else
                  Kazu(i,j)=Kazu(i-1,j-1)+Kazu(i-1,j)+Kazu(i-1,j+1)
               end if
            end do
         end do

         Sowa(0)=0
         do j=1,10
            Sowa(j)=sum(Kazu(j,:))-Kazu(j,0)
         end do

         do j=1,9
            Sowa(j+1)=Sowa(j+1)+Sowa(j)
         end do

         do m=1,10
            if (k<=Sowa(m)) then  !何桁か確定
               check=Sowa(m-1)    !確定した直前までの通し番号を記憶
               do n=1,9
                  if (check+Kazu(m,n)>=k) then  !最高位の確定
                     write(*,'(I0)',advance='no') n
                     call solve(k-check,m-1,n)  !(探索する直前までのカウント&
                                                ! ,前桁,確定した数字)
                     stop
                  end if
                  check=check+Kazu(m,n)
               end do
            end if
         end do

      contains
      recursive subroutine solve(k1,mae,fix)
         implicit none
         integer::k1,mae,fix
         integer::l,check1

            if (mae==0) then
               write(*,*) ''
               return
            end if

            check1=0
            do l=max(0,fix-1),min(9,fix+1)
               if ((check1+Kazu(mae,l))>=k1) then
                  write(*,'(I0)',advance='no') l
                  call solve(k1-check1,mae-1,l)
                  stop
               end if
               check1=check1+Kazu(mae,l)
            end do
            stop

      end subroutine solve

   end program abc161d