Your initial answer, "freeing the slaves," is not entirely incorrect, as Lincoln does mention this as a possible means to achieve his primary goal. However, the key point to note is that Lincoln's ultimate priority is preserving the Union.
In the quote, Lincoln outlines multiple scenarios for achieving his primary goal of preserving the Union. He states that if he could save the Union without freeing any slave, he would do so. This indicates that Lincoln values the unity of the United States above the issue of slavery. He further explains that if freeing the slaves would help preserve the Union, he would also do it. This implies that Lincoln views the emancipation of slaves as a means to an end rather than an end in itself.
Although Lincoln acknowledges the possibility of freeing some slaves while leaving others in bondage, he does not explicitly state that this is his preferred approach. Therefore, the preservation of the Union remains his primary objective, as this goal takes precedence over all other options, including the emancipation of slaves.