#pragma GCC optimize("O3,inline")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
using ii = pair<int, int>;
using iii = pair<int, ii>;
using pvii = pair<vector<int>, ii>;
constexpr int MAXN = 20000 + 5;
constexpr int INF = 1e18 + 5;
constexpr int LOG = 20;
signed main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
int N, M, K; cin >> N >> M >> K;
vector<pvii> inp(N);
for (int i = 0; i < N; ++i) {
vector<int> lol(M); for (int j = 0; j < M; ++j) cin >> lol[j];
sort(lol.begin(), lol.end());
int s = 0; for (int j = 0; j < M; ++j) s += lol[j];
inp[i] = pvii{lol, ii{s, i}};
}
sort(inp.begin(), inp.end(), [&](const pvii &a, const pvii &b) {
return a.second.first < b.second.first || a.second.first == b.second.first && a.second.second > b.second.second;
});
int best = N * M;
for (int m = 0; m < (1 << (N * M)); ++m) {
vector<pvii> inp2;
vector<int> order;
for (int i = 0; i < N; ++i) {
vector<int> waa0;
vector<int> waa1;
for (int j = 0; j < M; ++j) {
if ((m >> (i * M + j)) & 1) {
waa0.emplace_back(0);
waa1.emplace_back(K);
}
else {
waa0.emplace_back(inp[i].first[j]);
waa1.emplace_back(inp[i].first[j]);
}
}
order.emplace_back(inp[i].second.second);
order.emplace_back(inp[i].second.second);
sort(waa0.begin(), waa0.end());
sort(waa1.begin(), waa1.end());
int s0 = 0; for (int x : waa0) s0 += x;
int s1 = 0; for (int x : waa1) s1 += x;
inp2.emplace_back(pvii{waa0, ii{s0, inp[i].second.second}});
inp2.emplace_back(pvii{waa1, ii{s1, inp[i].second.second}});
}
sort(inp2.begin(), inp2.end(), [&](const pvii &a, const pvii &b) {
return a.second.first < b.second.first || a.second.first == b.second.first && a.second.second > b.second.second;
});
bool good = true;
for (int i = 0; i < 2 * N; ++i) {
if (inp2[i].second.second != order[i]) good = false;
}
if (good) best = min(best, N * M - __builtin_popcountll(m));
}
cout << best;
}