All problems

Problem 495

Lucky Numbers in a Matrix

Easy · 10 pts · Matrix

Problem

A matrix has distinct values. A lucky number is an element that is the smallest in its row and also the largest in its column. Print all lucky numbers in increasing order, or NONE if there are none. With distinct values there can be at most one lucky number, but any correct method is fine: compute each row's minimum and each column's maximum, then check every cell.

Input

First line: R and C. Next R lines: C distinct integers.

Output

Print the lucky numbers in increasing order, or NONE.

Constraints

1 <= R, C <= 50; 1 <= value <= 100000; all values are distinct

Example input

3 3
3 7 8
9 11 13
15 16 17

Example output

15

Explanation

In 3 7 8 / 9 11 13 / 15 16 17, the number 15 is the smallest in its row (15 16 17) and the largest in its column (3 9 15), so it is lucky.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Reshape the Matrix Next: Image Smoother