Deuteronomy 21:15-16
Laws Concerning Children
21:15 Suppose a man has two wives, one whom he loves more than the other, and they both bear him sons, with the firstborn being the child of the less loved wife.
21:16 In the day he divides his inheritance he must not appoint as firstborn the son of the favorite wife in place of the other wife’s son who is actually the firstborn.