NAURAS NERAPI lived a comfortable life in Aleppo as a manager at a French catering company. Then came the Syrian war. He fled through Turkey and the Balkans to Germany, arriving in September 2015. “They put me on a bus but I didn’t know where I was going,” he explains. At a reception camp in Berlin he offered to help with the cooking. Today he speaks good German, lives in a shared flat and works as a chef. “In Aleppo I was left with nothing. Germany has been really good to me.”

His arrival coincided with a pivotal point in Angela Merkel’s career. As thousands made their way north and west, the chancellor declared “We can manage this,” and kept Germany’s borders open. Some 900,000 people arrived that year. Many predicted social chaos and Mrs Merkel’s downfall. Her apparent cruise to victory at the election on September 24th is a testament to two factors. First, thanks largely to a repatriation deal with Turkey, the numbers coming fell to 200,000 last year and just 80,000 so far this year. Second, and more happily, despite the strains most of the refugees are on the path to integration.

That path begins at the reception camps, from where newcomers are allocated to hostels like Rudower 18, in eastern Berlin. “We had three days to turn a derelict school into a home,” says Andrea Koppelmann, its director. Today, children’s paintings on the walls make it cheerier, but conditions remain basic: two or three families to a classroom. Women with babies peer nervously from behind bedsheets strung up for privacy. Other hostels focus on gay and lesbian refugees, lone men or unaccompanied minors. Friedrich Kiesinger, a psychologist whose charity, Albatros, cared for some 40,000 people in reception centres, took over an empty hotel and turned it into a home for tortured, traumatised and disabled refugees.

Within three months those with good prospects of staying should move into “community homes” with private bedrooms and kitchens. But building these takes time. One family has been in Rudower 18 for over two years. The final step—moving to a private flat—might take four or five years, says Mr Kiesinger. And in any case, he adds, integration does not end at that point: “We don’t want little Afghanistans growing up behind doors.” Education and work are both essential.

The first is going well. Children are usually attending school within three weeks of arrival, says Ms Koppelmann. Several teenagers at Rudower 18 attend the nearby Anne Frank School, where Dagmar Breske, a teacher, has devised a three-stage programme. In a class for illiterates, three Afghan boys haltingly read out lists of words beginning with the letter “A”. In another, the second stage, seven teenagers—mostly Syrians and Iraqis—are practising multiplication. A third class, the highest, is going over verb forms in preparation for the test determining whether they can enter regular German schools. Much of the work is cultural: training the teenagers to follow German rules and treat women as equals.

Getting adults into work is harder. Only those granted asylum can take jobs. Once they have submitted their applications, those with good prospects (like many Syrians) take a compulsory integration course: 600 hours of German lessons and 100 hours of civics. Many refugees have had little education (see chart 1) and progress towards work could take time (see chart 2). Mr Kiesinger blames the obsession with formal language qualifications: “The best way to learn German is to get a job.”