#include using namespace std; #define rep(i,n) for(ll i=0;i<(n);++i) using ll = long long; constexpr ll INF = (1LL<<60); constexpr ll MOD = (1e9+7); templateinline bool chmax(T &a,const T &b){if(ainline bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;} inline void dump(){cout<inline void dump(Head&& head, Tail&&... tail){cout<(tail)...);} templateinline istream &operator>>(istream&input,vector&v){for(auto &elemnt:v)input>>elemnt;return input;} templatevector make_vector(size_t a){return vector(a);} templateauto make_vector(size_t a, Ts... ts){return vector(ts...))>(a, make_vector(ts...));} ll ans; int n,m,k; void dfs(ll t,int i,vector>& a){ if(k-t<0)return; if(i+1==n){ chmin(ans,k-t); return; } for(int nx=m-1;nx>=0;--nx){ dfs(t+a[i+1][nx],i+1,a); } } main(){ cin>>n>>m>>k; auto a = make_vector(n,m); cin>>a; ans=INF; dfs(a[0][0],0,a); if(ans==INF){cout<<(-1)<; // value,i_index priority_queue que; rep(j,m){ que.emplace(a[0][j],0); } while(!que.empty()){ auto [val,idx]=que.top();que.pop(); idx++; if(k-val<0)continue; if(idx==n){chmin(ans,k-val);continue;} for(int j=0;j