using System; using System.Linq; using System.Collections.Generic; namespace Algorithm { class Program { static int N, M, K; static int[][] A; static int[,] dp = new int[11, 501]; static void Main(string[] args) { var l = Console.ReadLine().Split().Select(int.Parse).ToArray(); N = l[0]; M = l[1]; K = l[2]; A = new int[N][]; for (var i = 0; i < N; i++) A[i] = Console.ReadLine().Split().Select(int.Parse).ToArray(); var ans = Dfs(0, 0); Console.WriteLine(ans == 0 ? -1 : K - ans); } static int Dfs(int n, int total) { if (total > K) return -1; if (n == N) { if (total <= K) return total; else return -1; } var max = 0; for (var i = 0; i < M; i++) { var t = 0; if (dp[n, total] != 0) t = dp[n, total]; else dp[n, total] = t = Dfs(n + 1, total + A[n][i]); max = Math.Max(max, t); } return max; } } }