An extension of the Kemp-Wan theorem on the formation of customs unions