program main
    implicit none
    integer(8) k
    integer, dimension(19) :: a
    integer(8) i,j,l,m,c,d,n,u,flag
    read(*,*) k

    c = 1
    a = 10
    a(1) = 0

    do i = 1,k

        u = 0
        do j = 1, c
            u = u + a(j)
        end do

        if (u == 9*c) then
            c = c + 1
            a(c) = 1
            do j = c-1,1,-1
                if(a(j+1) == 0) then
                    a(j) = 0
                else
                    a(j) = a(j+1) - 1
                end if
            end do
        else

            d = 0
            do l = 1, c
                if(a(l+1) == a(l) - 1) then
                    d = l + 1
                else
                    exit
                end if
            end do
            
            if (d /= 0) then
                a(d) = a(d) + 1
                do l = d-1, 1, -1
                    a(l) = a(l+1) -1
                    if(a(l) == -1) then
                        a(l) = 0
                    end if
                end do
            else if ( a(1) == 9 .and. a(2) == 9) then
                flag = 0
                do l = 3, c
                    if(a(l) == 9) then
                    else if(a(l+1) == a(l) - 1) then
                        flag = l + 1
                    else
                        if (flag == 0) then
                        a(l) = a(l) + 1
                        do m = l-1,1,-1
                            a(m) = a(m+1) - 1
                            if(a(m) == -1) then
                                a(m) = 0
                            end if
                        end do
                        end if
                        exit
                    end if
                end do
                if (flag /= 0) then
                    a(flag) = a(flag) + 1
                    do l = flag-1,1,-1
                        a(l) = a(l+1) - 1
                        if(a(l) == -1) then
                            a(l) = 0
                        end if
                    end do
                end if
            else
                a(1) = a(1) + 1
            end if

        end if

    end do

    n = 0
    do j = 1, c
        n = n + 10**(j-1)*a(j)
    end do

    write(*,*) n

end program