Solution: Let's represent the permutation needed to restore everyone as a sequence of cycles. Consider a cycle (abcd...lm), and call the two outsiders x and y. Swap x,a giving (xbcd...lm). Then swap y's body with b,c,d... in sequence, giving (xybcd...l). Lastly, swap y's body with the first body in the sequence and x's body with the second, giving (mabcd...l) as desired and leaving x and y with their minds in each other's body. Repeat this procedure for each cycle in the permutation, each time fixing up that cycle and swapping x and y with each other. At the end, either x & y are in the right bodies (even number of cycles) or not (odd), and if not a final use of the machine on their bodies fixes them.