#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const long long MAX = 510000; const long long INF = 1LL << 60; const long long MOD = 1000000007LL; using namespace std; typedef unsigned long long ull; typedef long long ll; int n, m, k; vector> dp; int dfs(vector>& v, int depth, int sum) { if (depth == n) return sum; //cout << depth << " " << sum << endl; if (dp[depth][sum] != -1) return dp[depth][sum]; int max_v = 0; for (int i = 0; i < m; i++) { int tmp = sum + v[depth][i]; if (tmp > k) continue; int x = dfs(v, depth + 1, tmp); max_v = max(max_v, x); } return dp[depth][sum] = max_v; } int main() { cin >> n >> m >> k; vector> v(n, vector()); dp = vector>(n, vector(k + 1, -1)); int ans = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { int x; cin >> x; if (j == 0) ans += x; v[i].push_back(x); } } if (ans > k) { cout << -1 << "\n"; return 0; } ans = dfs(v, 0, 0); cout << k - ans << "\n"; return 0; }