Call all

squares that we will skip be Hiura.
We will solves for

grid. The answer is
.
Label the coordinates on the square grid, with the bottom-left square be the origin.
We call a sequence of points be "uphill path", if
, then
,
, for all
. Similarly with "downhill path".

From

Hiura squares, there exists an uphill path with length
, and a downhill path with length

such that
.

Consider the "weight" of the

Hiura squares be its
-coordinate. The claim become this following problem. Given a sequence
. Then, there exist a pair of an uphill path and a downhill path which are the subsets of

(with the same order), have

and

elements, res, so that
. Assume that the
. We will need to prove that
. Then some using of Dirichlet principle give us the desired result. And the equation

occurs iff
, from this we can show that these two subsequences share a common element.
Back to our main problems, we shows that there exist an uphill path and a downhill path satisfy that, then these two lines divide the grid into 4 parts (with the color of top, left, bottom, right be red, green, purple, black), as the figure shown.
For each unit square from

Hiura squares, we label its edge depend on which parts it is in (if a unit square lies on

parts, we label all of its edges which share a same direction with the parts). Then, we can see that, each rectangle can cover at most 1 edge.
Now, our works is just count the minimal number of edges need to be cover.
There are at most 4 edges don't need to be cover among all labeled edges (that's the edge belong to the boundary of the grid), and there are at least

squares have 2 labeled edges, therefore the minimal number of edges need to be cover is
if the equation doesn't occur.
And if the uphill path and downhill path have a common square, then all of its edge is labeled.
Then, the minimal number of edges need to be cover is
as desired.
For the construction, we do the same with the case

below.