You are given an N×M matrix whose entries are each 0, 1, or 2. At least one entry equals 2.
Choose two axis-aligned rectangles (they may overlap, and they may even be identical) so that:
The area of a rectangle is the number of cells it covers. Among all valid choices, minimize the area of the region covered by the two rectangles together (a cell covered by both rectangles is counted once).
Report that minimum combined area, or report that no valid pair of rectangles exists.
The first line contains two integers N and M. Each of the next N lines contains M integers, giving the matrix row by row; every value is 0, 1, or 2.
Print a single integer: the minimum combined area of the two rectangles, or −1 if no valid pair exists.