Traversing a NxM matrix using diagonals.