Removed unnecessary print statement. nextValid() logic corrected.
Always finish the current row, then advance to others.
The initial marking procedure is wasteful and exceeds stack limits.
Before moving, mark 8: top, left, right bot, then left and right of top and
left and right of bottom.