#include "bits/stdc++.h" #define MOD 1000000007 #define rep(i, n) for(ll i=0; i < (n); i++) #define rrep(i, n) for(ll i=(n)-1; i >=0; i--) #define ALL(v) v.begin(),v.end() #define rALL(v) v.rbegin(),v.rend() #define FOR(i, j, k) for(ll i=j;i llvec; typedef vector dvec; typedef pair P; typedef long double ld; struct edge{ll x, c;}; vector A; ll N, M, K; llvec v; llvec v1; llvec v2; void dfs(ll n){ if(n==N/2){ ll s = 0; rep(i, n){ s += A[i][v[i]]; } v1.push_back(s); return; }else{ rep(i, M){ v.push_back(i); dfs(n+1); v.pop_back(); } return; } } void dfs2(ll n){ if(n==N-N/2){ ll s = 0; rep(i, n){ s += A[i+N/2][v[i]]; } v2.push_back(s); return; }else{ rep(i, M){ v.push_back(i); dfs2(n+1); v.pop_back(); } return; } } /************************************** ** A main function starts from here ** ***************************************/ int main(){ cin >> N >> M >> K; A = vector(N, llvec(M)); rep(i, N){ rep(j, M){ cin >> A[i][j]; } } dfs(0); dfs2(0); //v1.push_back(0); //v2.push_back(0); sort(ALL(v1)); sort(ALL(v2)); ll ans = 1e18; for(auto iv: v1){ if(iv>K)break; auto iter = upper_bound(ALL(v2), K - iv) - v2.begin(); if(iter!=0){ ans = min(ans, K - (v2[iter-1] + iv)); } } if(ans>1e16)ans = -1; cout << ans << endl; return 0; }