A rock travelled through an n x n board, stepping at each turn to the cell neighbouring the previous one by a side, so that each cell was visited once. Bob has put the integer numbers from 1 to n^2 into the cells, corresponding to the order in which the rook has passed them. Let M be the greatest difference of the numbers in neighbouring by side cells. What is the minimal possible value of M?