Looking tired but triumphant, the first two groups of Cubans permitted to leave Havana after seeking asylum in the Peruvian Embassy arrived here today.

As they walked down the steps from the chartered Boeing 727s, the Cubans held up their hands in victory gestures and shouted, "Viva Costa Rica."

Some of the refugees said their departure from Havana was a harrowing ordeal in which buses taking them to the airport ran a gauntlet of thousands of Cubans throwing stones and shouting, "We don't want you," The Associated Press reported.

Carlos Aguilar, a Costa Rican Foreign Ministry official who accompanied the dissidents from Cuba, said the scene at Havana airport was "like nothing I have ever seen before."

[He said about 300 people formed two rows and shouted obscenities at the exiles as they walked to the plane. Refugee Juan Alberto Rodriquez, his face cut and his knee bloody and bandaged, said he had been beaten by the crowd as he boarded the plane in Havana.]

Costa Rican President Rodrigo Carazo met the refugees, and later attended a mass at a home for the elderly, where they were to spend the night. A total of 154 Cubans arrived on the first flight and 82 on the second, 1 1/2 hours later. Most were men in their twenties and thirties, and there were about 80 women and two dozen children.

Many looked gaunt and tired after spending more than a week crowded together in the garden of the Peruvian Embassy with little food and under terrible sanitary conditions.

Carazo told reporters at the airport that Costa Rica would provide facilities for the Cubans on their way to other countries, but could only permit 300 of the 10,800 who took refuge in the Peruvian Embassy to stay. Most of them are expected to fly on to Peru Thursday.

Some said they expect to be among the 3,500 who will be admitted to the United States, because they have relatives there. They will join about 800,000 Cubans who have emigrated to the United States since President Fidel Castro took power in 1959.

Peru has said 1,000 of the refugees may settle there, and Spain, Ecuador, Canada, and Belgium have promised to take smaller numbers.

The overrunning of the Peruvian Embassy in Havana April 4 by Cubans seeking to leave the country has seriously strained Cuba's relations with Peru and Venezuela, which also has granted asylum to a number of Cubans.

It has also stirred emotional debate throughout Latin America. Those who dislike Castro's communist government says the rush to the embassy proves Castro's revolution is a failure, while Castro's supporters quote the Cuban government's charge that the people who want to leave are "vagabonds" and "delinquents.'

In fact, many of the young men who arrived today looked somewhat seedy, but that may have been because of the difficult conditions under which they had been living.

Carlos Miguel Gutierrez, 22, a well dressed law student, described the people he lived with in the embassy garden as "some students, some professional people, some housewives, some working women and the rest what you call in English 'low class' . . . people with problems."

Guiterrez said he is the oldest son of Cuban Construction Minister Carlos Miguel Gutierrez. "When I decided to leave my father said he does not share my ideas, but that I am his son and he supports me," Gutierrez said.

He said he decided to seek asylum because there is no freedom of expression or freedom in Cuba.

"I could say what I wanted to in my house," he said. "But if I said in the streets that the economic situation is bad, a policeman would put me in jail for slandering the revolution. I could not travel abroad to visit my relative." Gutierrez said he has eight uncles in the United States and hopes to join them.

Before eating a chicken supper, about half of the refugees crowded into a room at the Bethlehem Home where they are staying to hear mass. Although practicing religion is discouraged in Cuba, many of them knew the responses and crossed themselves.

When the mass ended all stood at attention and sang the Cuban national anthem, then chanted "Freedom, freedom, freedom."

Carazo told reporters that the two planes had returned to Cuba and would fly back with more refugees early Thursday morning. He said the flights would continue without interruption until all the Cubans who wished to leave had done so.

The "air bridge" is being organized by the Intergovernmental Committee for European Migration. Jose Montell of the committee said the operation would cost $4 million, about two thirds of it for transportation.