#include using namespace std; typedef long long ll; typedef pair pii; typedef pair pll; #define pb push_back #define mp make_pair #define rep(i,n) for(int i=0;i<(n);++i) constexpr int mod=1000000007; constexpr int mod1=998244353; vector dx={0,1,0,-1},dy={-1,0,1,0}; bool inside(int y,int x,int h,int w){ if(y=0 && x=0) return true; return false; } vector> a(10,vector(10)); int n,m,k; void dfs(vector&b, int t, int sum, int o){ if(t == o){ b.pb(sum); return; } rep(i,m){ dfs(b,t + 1, sum + a[t][i],o); } } int main(){ cin.tie(0); ios::sync_with_stdio(false); cin >> n >> m >> k; rep(i,n){ rep(j,m){ cin >> a[i][j]; } } int o = min(n,5); vector b; vector c; dfs(b,0,0,o); int ans = 100000; if(n <= 5){ rep(i,b.size()){ if(b.at(i) <= k) ans = min(ans, k - b.at(i)); } if(ans == 100000) cout << -1 << endl; else cout << ans << endl; return 0; } dfs(c,o,0,n); sort(b.begin(),b.end()); sort(c.begin(),c.end()); rep(i,c.size()){ if(c.at(i) > k) break; int t = lower_bound(b.begin(),b.end(),k - c.at(i)) - b.begin(); if(t == b.size()) t--; else if(b.at(t) != k - c.at(i)) t--; if(t >= 0) ans = min(ans, k - b.at(t) - c.at(i)); } if(ans == 100000) cout << -1 << endl; else cout << ans << endl; }