program atcoder0404_D
  integer(8),dimension(1000000)::A
  read(5,*)K
  do I=1,9
     A(I)=I
  end do
  M=10
  do I=1,K
     if(mod(A(I),10)/=0) then
        A(M)=10*A(I)+mod(A(I),10)-1
        M=M+1
     end if
     A(M)=10*A(I)+mod(A(I),10)
     M=M+1
     if(mod(A(I),10)/=9) then
        A(M)=10*A(I)+mod(A(I),10)+1
        M=M+1
     end if
     if (M>=K+1) exit
  end do
  write(6,*)A(K)
end program atcoder0404_D