#include using namespace std; #define rep(i, n) for(int i = 0; i < (int)n; ++i) #define FOR(i, a, b) for(int i = a; i < (int)b; ++i) #define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i) typedef long long ll; typedef long double ld; const int Inf = 1e9; const double EPS = 1e-9; const int MOD = 1e9 + 7; int n, m, k; int res = Inf; vector > a; void dfs(int pos = 0, int c = 0) { if (pos == n) { int cost = k - c; if (cost >= 0) res = min(res, cost); return; } rep (i, m) { dfs(pos + 1, c + a[pos][i]); } } int main() { cin.tie(nullptr); ios::sync_with_stdio(0); cin >> n >> m >> k; a = vector >(n, vector(m)); rep (i, n) rep (j, m) cin >> a[i][j]; dfs(); if (res == Inf) cout << -1 << endl; else cout << res << endl; return 0; }