import java.util.Scanner;

public class TerrainElevation {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // Read rows and columns
        int r = scanner.nextInt();
        int c = scanner.nextInt();

        // Check for invalid input
        if (r <= 0 || c <= 0) {
            System.out.println(-1);
            return;
        }

        int minElevation = Integer.MAX_VALUE;

        // Read r × c elevation values and find the minimum
        for (int i = 0; i < r * c; i++) {
            int elevation = scanner.nextInt();
            if (elevation < minElevation) {
                minElevation = elevation;
            }
        }

        System.out.println(minElevation);
    }
}