#C5782. Minimum Cost Matrix Removal
Minimum Cost Matrix Removal
Minimum Cost Matrix Removal
You are given an n x m matrix consisting of non-negative integers. Your task is to compute the minimum cost to remove all elements from the matrix, where removal is performed by deleting an entire row or column at a time.
The strategy that minimizes the total cost is to always remove the row or column containing the smallest element. In other words, the answer is simply the minimum element in the matrix. Formally, if the matrix is represented as \(a_{ij}\), then the minimum cost is given by:
$$ \min_{1 \le i \le n,\ 1 \le j \le m} a_{ij} $$
Input is provided via standard input and output should be printed to standard output.
inputFormat
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 1000), representing the number of rows and columns in the matrix respectively. This is followed by n lines, each containing m non-negative integers separated by spaces, representing the matrix elements.
outputFormat
Output a single integer: the minimum element in the matrix, which represents the minimum cost.
## sample2 2
3 2
4 1
1