#include using namespace std; int main() { //入力 int N,M,K; cin >> N >> M >> K; assert(1<=N&&N<=20); assert(1<=M&&M<=20); assert(1<=K&&K<=1000); vector> a(N,vector(M)); for(int i = 0; i < N; ++i) { for(int j = 0; j < M; ++j) { cin >> a[i][j]; assert(1 <= a[i][j] && a[i][j] <= 20); } } //ソート、差分計算、初期値 int sum = 0; for(int i = 0; i < N; ++i) { sort(a[i].begin(),a[i].end()); int ini = a[i][0]; sum += ini; for(int j = 0; j < M; ++j) a[i][j] -= ini; } cout << max(K-sum,-1) << endl; return 0; }