Central American countries have agreed to a pilot program to start allowing thousands of Cuban migrants stranded in Costa Rica to continue onward to the United States from next month, governments in the region said on Monday. The deal, reached between officials meeting in Guatemala City, will provide flights for an undisclosed number of Cubans to El Salvador, where they will then be ferried toward Mexico by bus, Costa Rica's Foreign Ministry said in a statement. The program is due to begin during the first week in January, the governments of Guatemala and Mexico said. Approximately 250 Cuban migrants will be flown to El Salvador initially, said Guatemalan Foreign Minister Carlos Morales. Costa Rica's government, which stopped issuing transit visas to Cubans earlier this month, said providing shelter for the migrants has badly stretched local resources. "The solution emerging is an absolute exception and only for those people who entered national territory legally," Costa Rica's foreign minister, Manuel Gonzalez, said. It was not immediately clear how the migrants' travel will be paid for, but diplomats are expected to work out logistical details in upcoming meetings, the Mexican government said. Mexico said the pilot program will be subject to revision. Since mid-November, the number of Cuban migrants stuck in limbo inside Costa Rica's northern border with Nicaragua has grown steadily. An estimated 8,000 Cubans are now stuck there. The flow of migrants from the Communist-ruled island has surged as the process of a detente between Washington and Havana, announced last December, stirs fears that preferential US asylum rights for Cubans may soon end. Migrants became stranded in Costa Rica after Nicaragua, which is a close ally of Cuba, shut its borders in November, saying that Costa Rica had sparked a "humanitarian crisis" after Costa Rica issued transit visas to more than 1,000 Cubans. On Sunday, Pope Francis urged the region to resolve the "humanitarian drama" in Costa Rica quickly. Officials from Panama, El Salvador, Guatemala, Honduras, Belize, Mexico, Costa Rica and the International Organization for Migration took part in the talks, Guatemala said.