MEXICO CITY - Acknowledging uncertainty ahead, President Obama said Thursday the United States would cooperate with Mexico in fighting drug-trafficking and organized crime in any way Mexico's government deems appropriate.

Mexican President Enrique Pena Nieto emphasized that the security relationship must be expanded to focus on trade and commerce.

Appearing alongside Pena Nieto at a news conference, Obama recommitted the United States to fighting the demand for illegal drugs in his country and the flow of illegal guns across the border to Mexico, even as the southern neighbor rethinks how much access it gives to American security agencies.

"I agreed to continue our close cooperation on security, even as the nature of that cooperation will evolve," Obama said. "It is obviously up to the Mexican people to determine their security structures and how it engages with other nations - including the United States."

Obama's remarks come as Pena Nieto, in a shift from his predecessor, has moved to end the widespread access that U.S. security agencies have had in Mexico to help fight drug-trafficking and organized crime. The White House has been cautious in its public response to the changes, with the president and his advisers saying they need to hear directly from the Mexican leader before making a judgment.

Pena Nieto, speaking at the news conference, said his government's new security strategy emphasizes reducing violence. But he downplayed the notion that it would mean a diminished effort to fight organized crime. "There is no clash between these two goals," he said.

The two leaders met Thursday on the first day of Obama's three-day trip to Mexico and Costa Rica, his first visit to Latin America since winning reelection.