//Normal #define _GLIBCXX_DEBUG #define ll long long #include using namespace std; using Graph = vector>; void print(auto a){ cout << a; } void prints(auto a){ cout << a << " "; } void prints(){ cout << " "; } void printl(auto a){ cout << a << endl; } void printl(){ cout << endl; } void fix(int n){ cout << fixed << setprecision(n); } int siz(string s){ return (int)s.size(); } int main(){ int N, M, K; cin >> N >> M >> K; vector> X(N, vector(M)); int minvsum = 0, maxvsum = 0; for(int i = 0; i < N; i++){ for(int j = 0; j < M; j++){ cin >> X[i][j]; if(j == 0) minvsum += X[i][j]; if(j+1 == M) maxvsum += X[i][j]; } } if(minvsum > K){ printl(-1); }else if(maxvsum <= K){ printl(K - maxvsum); }else{ vector> dp(N+1, vector(550, false)); dp[0][0] = true; for(int i = 0; i < N; i++){ for(int j = 0; j < 500; j++){ if(!dp[i][j]) continue; for(int k = 0; k < M; k++){ dp[i+1][j+X[i][k]] = true; } } } for(int i = K; i >= 0; i--){ if(!dp[N][i]) continue; printl(K - i); return 0; } } }