8,9
The side of a cell on a grid paper is 1. A rectangle with sides $m$ and $n$ is constructed along the grid lines.
Can a closed broken line be drawn within the rectangle along the grid lines that passes exactly once through each grid node located inside or on the boundary of the rectangle? If so, what is its length?
Notice that from each node of the grid located inside or on the boundary of the rectangle $n \times m$, exactly one segment of the path goes out, otherwise, this node is either not visited at all or visited more than once. The total number of nodes inside or on the boundary of the rectangle is $(n+1)(m+1)$, and thus the length of the broken line is $(n+1)(m+1)$. The length of such a broken line is even (see problem Z0932). Therefore, at least one of the numbers $m, n$ is odd.

If one of them is 1, then a traversal along the perimeter satisfies the condition. When one of them is odd and greater than 1, a traversal is possible as shown in the figure.

![](https://cdn.mathpix.com/cropped/2024_05_06_6fdbe810ffc70cc86b90g-06.jpg?height=400&width=329&top_left_y=2464&top_left_x=870)

## Answer

If $n$ and $m$ are even, such a broken line does not exist; if at least one of the numbers $n$ and $m$ is odd, such a broken line exists and its length is $(n+1)(m+1)$.