#include using namespace std; #define REP(i,a) for(int i = 0; i < (a); i++) #define ALL(a) (a).begin(),(a).end() typedef long long ll; typedef pair P; const int INF = 1e9; const int MOD = 1e9 + 7; int n,m,k; int a[10][10]; int dp[11][501]; int DFS(int depth, int use){ if(dp[depth][use] != -1){ return dp[depth][use]; } if(depth == n){ return k - use; } int res = INF; REP(i,m){ if(use + a[depth][i] <= k){ res = min(res, DFS(depth + 1, use + a[depth][i])); } } return dp[depth][use] = res; } signed main(){ cin >> n >> m >> k; REP(i,n){ REP(j,m){ cin >> a[i][j]; } } memset(dp, -1, sizeof(dp)); DFS(0, 0); if(dp[0][0] == INF){ cout << -1 << endl; }else{ cout << dp[0][0] << endl; } return 0; }