int main() {
	int N, M;
	int X, c[100];
	int A[100][12];
	int i, q, p, l;
	int wa[100], hon = 0;
	scanf("%d", &N);
	scanf("%d", &M);
	scanf("%d", &X);
	for (i = 0; i < N; i++) {
		scanf("%d", &c[i]);
		hon += c[i];
		for (q = 0; q < M; q++) {
			scanf("%d", &A[i][q]);
			wa[i] = 0;
			wa[i] += A[i][q];
		}
		if (wa[i] > 0) {
			printf("%d", hon);
			break;
		}
	}
	for (l = 0; l < M; l++) {
		if (wa[i] < M) {
			printf("-1");
			break;
		}
		else {
			printf("%d", hon);
			break;
		}

	}
}