/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static int m;
	public static int n;

	public static boolean check(int[][] matrix, int c){
		HashMap<Integer, Integer> k = new HashMap<>();
		TreeMap<String, Integer> u = new TreeMap<>();
	
		int ck = 0;
		int count = 0;
		int p = 0;
		
		for(int i = 0; i < n; i++){
			count = 0;
			for(int j = 0; j < m; j++){
				if(matrix[i][j] >= c){
					ck = j;
					count++;
				}
			}
			if(count == 1){
				k.put(ck, 1	);
			}
			if(count == 0){
				return false;
			}
		}
		
		p = k.size();
		for(int i = 0; i < n; i++){
			count = 0;
			int gp = 0, ck1 = 0, ck2 = 0;
			for(int j = 0; j < m; j++){
				if(k.getOrDefault(j, 0) == 0 && matrix[i][j] >= c){
				count ++;
				if(count == 1){
					ck1 = j;
				}
				if(count == 2){
					ck2 = j;
				}
				}
			if((k.getOrDefault(j, 0) == 1) && matrix[i][j] >= c){
				gp = 1;
			} 
		}

		
		if(gp == 1){
			
		}else{
			if(count == 2){
				String key = ck1 + "#" + ck2;
				u.put(key, u.getOrDefault(key, 0) + 1);
			}
		}
		}
		
		int kgp = u.size();
		int m1 = m - p;
		int v = (m1 * (m1 - 1)) / 2;
		
		if(kgp == v){
			return false;
		}
		return true;
	}
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		m = 4;
		n = 4;
		int[][] matrix = {
	    	{3, 4, 2, 2},
		    {3, 3, 3, 4},
		    {2, 4, 2, 3},
		    {4, 2, 4, 2}
			};
						
		int c = 0;
		while(check(matrix, c)){
			c++;
		}
		System.out.print(c - 1);
		
	}
}