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

~/algor $ cat problems/matritsa-egar-nuqtalari

Saddle points

Medium 1000 ms 128 MB 45%
Share

An integer matrix of size $n \times m$ is given. An element is a saddle point if it is the smallest in its row and at the same time the largest in its column (its row or column may contain elements equal to it). Find the number of saddle points in the matrix.

A saddle point: the smallest in its row and the largest in its column

Input

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

Output

One integer — the number of saddle points.

Note

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

Examples

Input #1
3 3
3 5 4
1 2 6
0 7 8
Output #1
1
Input #2
2 2
1 1
1 1
Output #2
4

Sign in to submit a solution

Signing up is free and takes a minute.