n,m,k=gets.split(" ").map{|e| e.to_i} dp=Array.new(k+1,-1) dp[0]=1 n.times{ xs=gets.split(" ").map{|e| e.to_i} dp2=Array.new(k+1,-1) xs.each{|x| (k-x).downto(0){|j| next if dp[j]==-1 dp2[j+x]=1 } } dp=dp2.dup } ans=-1 0.upto(k){|i| ans=i if dp[i]==1 } if ans==-1 then puts ans else puts k-ans end