题目描述
Problem Description
Zane is the principal of NOI School. The school has $n$ classes, each with $s$ students. The height of the $j$-th student in the $i$-th class is $a_{i,j}$.
Zane wants to select one student from each class to take a photo, such that the difference between the tallest and shortest student among these $n$ students is minimized.
Please output this minimum value.
Input Format
The first line contains two integers $n$ and $s$.
The next $n$ lines each contain $s$ integers, representing the array $a$.
Output Format
Output a single integer representing the answer.
Sample Input and Output
Sample Input #1
2 3
2 1 8
5 4 7
Sample Output #1
1
Sample Input #2
3 3
3 1 4
2 7 18
9 8 10
Sample Output #2
4
Notes
Sample #2 Explanation
Selecting $a_{1,3}, a_{2,2}, a_{3,2}$ results in an answer of $8-4=4$.
Data Range
| Subtask | Score | Special Conditions |
|---|---|---|
| $0$ | $0$ | Examples |
| $1$ | $11$ | $n=2$ |
| $2$ | $22$ | $n, s \leq 100$ |
| $3$ | $9$ | $n, s \leq 250$ |
| $4$ | $33$ | $n, s \leq 500$ |
| $5$ | $25$ | None |
For $100\%$ of the data, $1 \leq n, s \leq 1000, 1 \leq a_{i,j} \leq 10^9$.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分