Ferndale community school lies just inside the former mining village of Maerdy, near the top of the Rhondda Fach valley. Once known as "Little Moscow", because of the extreme strength of its unions and its position above the snow line, it is still, without mining or snow, a bleak place.
Of the two main factories in the area, Chubb security systems, is moving to China and the other, United Polymers, is cutting jobs. The school is now the largest single employer in the valley. There is no railway, so the 40 per cent of households in Maerdy without a car are stuck with an infrequent bus service. The official description of "relatively remote" is an understatement.
Yet the 11 to 18 comprehensive looks and feels lively. It has just won a glowing report from Estyn, the schools watchdog. Among the many outstanding features highlighted by the inspectors was "the amount of care and support given to all pupils, especially those with wide-ranging and complex needs".
Two out of the three communities the school serves rank among the most deprived wards in Wales. Pupil numbers are falling steadily: a building designed for 1,200 now caters for only 770.
But other numbers are rising. Despite a disappointing downward blip last year, results at GCSE and A-level have been steadily improving - at A-level, they sometimes surpass the Welsh average - and have consistently exceeded those of other schools facing similar challenges.
"All our rolling averages are progressing upwards," says the forceful head, Peter Jenkins, like the Cambridge mathematician he is. From 25 per cent when he arrived, the average for five good GSCEs is now in the low forties.
Born in the valleys, Mr Jenkins came to the school four years ago from a deputy headship in relatively prosperous Caerphilly.
"There it was all results, results, results," he says. "To get the results here, you have to take a much more inclusive, wraparound view."
That perspective was exemplified at the start of his tenure by a change of name - from comprehensive to community school - and has meant working with many partners, from within and outside education, to help pupils cope with their problems.
Under the On Track programme, a team of teachers, health and social workers and a psychologist identifies pupils aged 5 to 12 whose behaviour or family background puts them at risk and offers help and support to the child and family.
All pupils in their last two years at Ferndale's four feeder primaries take part in a transition programme during which an "inclusion co-ordinator" visits some families at home. When they arrive at Ferndale, pupils deemed at risk are closely monitored and given extra support if they need it.
In the year before On Track was introduced, there were 88 referrals of Ferndale pupils to social services. A year later, the figure was five. Mr Jenkins is determined to keep the programme going when National Assembly funding stops in 2007.
Now the school is taking part in On Track Plus, for children of 12 and over, where parents and children in targeted families attend a six-week series of one-day sessions on issues such as drugs and communication.
A multitude of other changes in the last four years - a new school uniform, a new behaviour and sanctions policy, the introduction of on-site vocational courses in conjunction with the local FE Coleg Morgannwg - have helped to improve both behaviour and performance, although truancy (mostly parentally condoned) remains a problem.
But Mr Jenkins rejects the notion that he is a superhead. "I just came in and used the energies of the pupils and staff that I have," he says. "I wanted to give the school an identity, give the area a pride. There's still a long way to go."