import java.io.*; import java.util.*; import java.util.function.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int h = sc.nextInt(); int w = sc.nextInt(); int k = sc.nextInt(); int[][] field = new int[h][w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { field[i][j] = sc.nextInt(); } } int left = 0; int right = 1000000001; Deque deq = new ArrayDeque<>(); while (right - left > 1) { int m = (left + right) / 2; deq.add(new Path(0, 0, 0)); int[][] counts = new int[h][w]; for (int[] arr : counts) { Arrays.fill(arr, Integer.MAX_VALUE); } while (deq.size() > 0) { Path p = deq.poll(); if (field[p.r][p.c] < m) { p.value++; } if (counts[p.r][p.c] <= p.value) { continue; } counts[p.r][p.c] = p.value; if (p.r > 0 && counts[p.r - 1][p.c] == Integer.MAX_VALUE) { deq.add(new Path(p.r - 1, p.c, p.value)); } if (p.r < h - 1 && counts[p.r + 1][p.c] == Integer.MAX_VALUE) { deq.add(new Path(p.r + 1, p.c, p.value)); } if (p.c > 0 && counts[p.r][p.c - 1] == Integer.MAX_VALUE) { deq.add(new Path(p.r, p.c - 1, p.value)); } if (p.c < w - 1 && counts[p.r][p.c + 1] == Integer.MAX_VALUE) { deq.add(new Path(p.r, p.c + 1, p.value)); } } if (counts[h - 1][w - 1] <= k) { left = m; } else { right = m; } } System.out.println(left); } static class Path { int r; int c; int value; public Path(int r, int c, int value) { this.r = r; this.c = c; this.value = value; } } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); public Scanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String next() { try { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (Exception e) { e.printStackTrace(); } finally { return st.nextToken(); } } }