Sacred Skyline


Submit solution

Points: 1
Time limit: 1.5s
Memory limit: 256M

Author:
Problem type
Allowed languages
C, C++, Java, Python

The year is 2567 BC, and you are an ancient Egyptian architect. You have been politely asked by Pharaoh Khufu to assist in the construction of a great monument in his honor. The Monument is constructed from towers of limestone blocks. However, Khufu is a deeply religious man, and would like for the entire monument to be blessed. There are two deities capable of blessing each of the towers in the monument:

Khepri's Blessing (Morning Sun): Khepri will bless a tower if it is illuminated during sunrise, which requires a given tower to be taller or at the same height as all towers to the south and west

Atum's Blessing (Evening Sun): Atum will bless a tower if it is illuminated during sunset, which requires a given tower to be taller or at the same height as all towers to the north and east

Unfortunately, Khufu's reign has just begun and as a result he is quite stretched for resources. He tasks Maged with determining the minimum amount of additional limestone blocks to add to the current monument plans in order for every constituent tower in the monument to be blessed.

Input

The first line contains two integes m and n (1 \leq m, n \leq 300), representing the number of rows and columns of monument towers respectively.

There are then m lines to represent a row of the monument.

Each row contains n integers, which are the heights h (0 \le h \le 10^5) of each tower in the current row.

Output

Output the minimum amount of additional blocks required for the entire monument to become blessed.

Examples

Input 1
3 3
0 1 0
1 0 1
0 1 0
Output 1
3

A possible solution is

1 1 0 
1 1 1
0 1 1

Resulting in 3 additional blocks

Input 2
3 3
0 1 0
1 0 1
2 1 2
Output 2
3

A possible solution is

1 1 0 
1 1 1
2 2 2

Resulting in 3 additional blocks

Input 3
3 4
1 0 0 2
1 3 0 0 
0 1 1 1
Output 3
8

A possible solution is

1 2 2 2 
1 3 2 2
0 1 1 1

Resulting in 8 additional blocks


Comments

There are no comments at the moment.