n,m,x=io.read("*n","*n","*n","*l")
a={}
for i=1,n do
    a[i]={}
    for j=1,m+1 do
        a[i][j]=io.read("*n")
    end
end
table.sort(a,function(x,y)
    return x[1]<y[1]
end)

total=0
x={}
for i=1,n do
    for j=1,m+1 do
        if j==1 then
            total=total+a[i][j]
        else
            x[j-1]=x[j-1]+a[i][j]
        end
    end
    counter=0
    for j=1,m do
        if x[j]>=x then
            counter=counter+1
        end
    end
    if counter==m then
        print(total)
        return
    end
end
print(-1)