The correct answer is "to eliminate unfriendly governments geographically close to the United States."
The Bay of Pigs invasion was the United States attempt to overthrow the reign of Fidel Castro. Castro's establishment of a communist system and his decision to cut economic ties with the US worried the federal government. They wanted to overthrow Castro so that they could replace him with someone who would be more willing to trade/work with the US.
The invasion of Panama had a similar sentiment, as the US government hoped to overthrow the military dictator Manuel Noriega.