cho.sh
Notes
Loading...

Representative Players

Time limit

2s

Memory limit

256 MB

Problem

KOI Middle School has N classes, and each class has M students. Every student has one ability score for a new sports event, and all ability scores are distinct.

The school will choose exactly one representative player from each class. Among the N chosen players, the difference between the maximum ability score and the minimum ability score should be as small as possible.

Write a program that computes this minimum possible difference.

Input

The first line contains two integers N and M, separated by a space: the number of classes and the number of students in each class. 1 <= N, M <= 1,000.

Each of the next N lines contains M integers separated by spaces, representing the ability scores of the students in one class. Each ability score is between 0 and 10^9, inclusive, and all ability scores are distinct.

Output

Output one integer: the minimum possible difference between the maximum and minimum ability scores among representatives chosen one from each class.