#include using namespace std; using ll = long long; using VI = vector; using VL = vector; #define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i)) #define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i)) #define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i)) #define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i)) #define SORT(i) sort((i).begin(),(i).end()) #define rSORT(i,a) sort((i).begin(),(i).end(),(a)) #define all(i) (i).begin(),(i).end() constexpr ll INF = 1000000000; constexpr ll LLINF = 1LL << 60; constexpr ll mod = 1000000007; constexpr ll MOD = 998244353; 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; } inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } templateinline istream& operator>>(istream& input, vector& v) { for (auto& elemnt : v)input >> elemnt; return input; } int main() { init(); int n, m, k; cin >> n >> m >> k; vector> a(n, deque(m)); int ans = 0; FOR(i, 0, n) { FOR(j, 0, m)cin >> a[i][j]; ans += a[i][0]; FOR(j, 1, m)a[i][j] -= a[i][0]; a[i].pop_front(); } --m; if (ans > k)ans = k + 1; else { vector> dp(n + 1, vector(501)); dp[0][ans] = true; FOR(i, 0, n)eFOR(j, 0, 500) { if (dp[i][j]) { FOR(l, 0, m) { dp[i + 1][j + a[i][l]] = true; } dp[i + 1][j] = true; } } eFOR(i, 0, k)if (dp[n][i])chmax(ans, i); } cout << k - ans << "\n"; }