P10710 [NOISG 2024 Prelim] School Photo

Background

Translated from [NOI SG 2024 Prelim C.School Photo](https://github.com/noisg/noi-2024-prelim).

Description

Zane is the principal of the NOI school. The NOI school has $n$ classes, and each class has $s$ students. The height of the $j$-th student in the $i$-th class is $a_{i,j}$. Now Zane wants to choose one student from each class for a photo, such that among these $n$ students, the difference between the tallest student's height and the shortest student's height is minimized. Output this minimum value.

Input Format

The first line contains two integers $n, s$. The next $n$ lines each contain $s$ integers, representing $a$.

Output Format

Output one integer in a single line, representing the answer.

Explanation/Hint

### Sample #2 Explanation Choose $a_{1,3}, a_{2,2}, a_{3,2}$. The answer is $8-4=4$. ### Constraints |$\text{Subtask}$|Score|Special Property| |:-:|:-:|:-:| |$0$|$0$|Samples| |$1$|$11$|$n=2$| |$2$|$22$|$n, s \le 100$| |$3$|$9$|$n, s \le 250$| |$4$|$33$|$n, s \le 500$| |$5$|$25$|None| For $100\%$ of the testdata, $1 \le n, s \le 1000$, and $1 \le a_{i,j} \le 10^9$. Translated by ChatGPT 5