The answer is ⌊2(n+1)(m+1)⌋−1.
For a shelf R, let R~ be the rectangular area by extending R by 1 row to the top and 1 column to the left. Let us also extend the initial chessboard by 1 row to the top and 1 column to the left. We assign −∞ to each of those new unit squares so that the number of shelves is preserved. For a shelf R, let us call the integer h satisfying two conditions the *height* of R.
Claim 1: If two shelves R1 and R2 do not intersect, then R~1∩R~2=∅.
Proof of Claim 1: Let h1,h2 be the height of R1,R2 respectively. Without loss of generality, let us assume h1≤h2. If R~1∩R~2=∅, then some unit square x in R2 is adjacent to R1 and therefore the integer in x is less than or equal to h1. Since x∈R2, the integer in x is larger than h2, contradictory to the assumption that h1≤h2. This proves Claim 1.
Claim 2: If R1 and R2 are distinct maximal shelves smaller than the whole chessboard, then R1∩R2=∅.
Proof of Claim 2: Let h1,h2 be the height of R1,R2 respectively. Without loss of generality, let us assume h1≤h2. Suppose that R1∩R2=∅. Suppose a unit square x in R2 shares at least one point with R1. If x does not belong to R1, then the integer in x should be at most h1 but since x∈R2, the integer in x should be larger than h2, contradictory to the assumption that h1≤h2. So such x belongs to R1 and therefore R2⊆R1. However this contradicts to the assumption that R2 is maximal. So Claim 2 is proved.
Claim 3: The number of shelves in the n×m chessboard is less than or equal to 2(n+1)(m+1)−1.
Proof of Claim 3: We proceed by induction on n+m. If n+m=2, then n=m=1 and the number of shelves is 1.
Now let us assume n+m>2. Let R1,R2,…,Rk be the maximal shelves strictly smaller than the whole n×m chessboard.
By Claims 1 and 2, R~i∩R~j=∅. By the induction hypothesis, the number of shelves contained in Ri for each i is at most ∣R~i∣/2−1. Therefore the number of all shelves is at most
i=1∑k(⌊2∣R~i∣⌋−1)≤2(n+1)(m+1)−k−1.
So Claim 3 is proved if k>1. We may now assume that k=1. Then it is enough to show that
max(2m(n+1)⋅2(m+1)n)−1+1≤2(n+1)(m−1)−1.
It is easy to see this because n≥1 is equivalent to the inequality that 2m+n−1≤2(n+1)(m+1)−1. This proves Claim 3.
Now it remains to show that there is an assignment of integers so that the number of shelves is exactly ⌈2(n+1)(m+1)⌉−1. We proceed by induction on n+m. It is trivial if max(n,m)≤2.
Now by symmetry let us assume that m>2. Let us write 1 in each unit square on the second row. For the first row, we write integers larger than 1 obtained by the induction hypothesis on a 1×n chessboard. For the remaining rows, we write integers larger than 1 obtained by the induction hypothesis on a (m−2)×n chessboard.
Now the number of shelves in this assignment is
1+⌊22(n+1)−1⌋+⌈2(m−1)(n+1)−1⌉
by the induction hypothesis. This completes the proof. □