#include using namespace std; #define DUMP(x) std::cout << (#x) << " = " << (x) << "\n" #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define REP(i, k, n) for (int i = (k); i < (int)(n); ++i) #define ALL(r) r.begin(), r.end() #define YES puts("YES") #define Yes puts("Yes") #define NO puts("NO") #define No puts("No") #define IMP puts("IMPOSSIBLE") #define Imp puts("Impossible") #define imp puts("impossible") #define pb push_back template T dup(T x, T y) { return (x + y - 1) / y; }; template inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } template inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } using ll = int64_t; using vint = vector; using vvint = vector; using vll = vector; using vvll = vector; using vstr = vector; using pint = pair; using pll = pair; using vpint = vector; using vpll = vector; using sint = set; using sstr = set; using qint = queue; constexpr std::int32_t INF = 1001001001; constexpr std::int64_t LINF = 1001001001001001001; int n, m, k; int ans; int a[12][12]; void dfs(int x, int sum) { if (x == n) { if (sum > k) return; else { chmax(ans, sum); return; } } if (sum > k) return; rep(i, m) { dfs(x + 1, sum + a[x][i]); } return; } void Main() { cin >> n >> m >> k; ans = -1; rep(i, n) rep(j, m) cin >> a[i][j]; /* n = 10; m = 10; k = 500; rep(i, n) rep(j, m) a[i][j] = i * 2 + j; */ dfs(0, 0); if (ans == -1)cout << -1 << endl; else cout << k - ans << endl; } int main() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(15); Main(); return 0; }