Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/matritsa-qator-maksimumlari-minimumi

Smallest of the row maximums

Easy 1000 ms 128 MB 26%
Share

An integer matrix of size $n \times m$ is given. Among the largest elements of the rows, find the smallest one:

$$V = \min_{1 \le i \le n} \left( \max_{1 \le j \le m} a_{i,j} \right)$$

Choosing the smallest of the row maximums

Input

The first line contains two positive integers $n$ and $m$. Each of the next $n$ lines contains $m$ integers.

Output

One integer — the smallest of the row maximums.

Note

$1 \le n, m \le 200$
$-1000 \le a_{i,j} \le 1000$

Examples

Input #1
3 3
1 7 3
4 2 5
9 8 6
Output #1
5
Input #2
1 3
-1 -2 -3
Output #2
-1

Sign in to submit a solution

Signing up is free and takes a minute.