# ifndef ONLINE_JUDGE # define _GLIBCXX_DEBUG # endif #include using namespace std; using ll = long long; using vi = vector; using vvi = vector>; using pii = pair; # define rep(i, n) for(int i = 0; i < (int)(n); i++) # define all(v) v.begin(), v.end() int main(){ constexpr char endl = '\n'; ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(10); //input(); int N, M, K;cin >> N >> M >> K; vvi cost(N, vi(M)); for(auto &&e : cost) for(auto &&ee : e) cin >> ee; //solve(); vvi dp(N+1, vi(K+1)); //dp[i+1][j]:=i番目の国まで行ったとき、j円かかるか dp[0][0] = 1; bool ok; rep(i, N){ ok = false; for(int j = 0; j <=K; ++j){ rep(m, M){ if(dp[i][j] && j+cost[i][m] <= K){ dp[i+1][j+cost[i][m]] = 1; ok = true; } } } if(!ok) break; } //output(); if(!ok) cout << -1 << endl; else{ for(int j = K; 0 <= j; --j){ if(dp[N][j]){ cout << K-j << endl; break; } } } }