#include #include using namespace std; using namespace atcoder; #define ll long long #define rep(i,n) for (int i = 0; i < (n); i++) #define coutf(f) cout << fixed << setprecision(f) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() int main() { int n, m, k; cin >> n >> m >> k; vector> a(n, vector(m)); rep(i, n) rep(j, m) cin >> a[i][j]; vector> v(n); rep(i, m) v[0].insert(a[0][i]); for (int i = 1; i < n; i++) { for (auto t : v[i - 1]) { rep(j, m) { v[i].insert(t + a[i][j]); } } } int mx = 0; for (auto t : v[n - 1]) { if(t <= k) mx = max(mx, t); } int ans = k - mx; if (k == ans) cout << -1 << endl; else cout << ans << endl; return 0; }