Automatically set the grid number based on the lines' number