The first and the last person in the queue are not standing between any other persons.
All the other persons in the queue are always between any two preceding and succeeding members in the queue.
Thus, there are 23 persons in the queue who are found to be standing between any two members in the queue.
If the number of persons is M, then the two persons at the two extremes will not come between any two members of the queue.
So, (M2) persons in the queue are found to be standing between any two members in the queue.