This summer, Melvin Matos did something that he once thought he would never do: graduate from high school.

He’d started drinking at 14 and quickly moved on to pills and pot. By the time he turned 16, Matos could see where his life was heading: Some of his buddies already had died because of drugs and drink.

After a stint in rehab, Matos enrolled at the William J. Ostiguy High School in Boston, one of five public “recovery high schools” in Massachusetts. There, in addition to his academic classes, he participated in group therapy and 12-step meetings, submitted to regular drug tests and formed friendships with kids facing struggles similar to his.

This fall, Matos is enrolling in a local community college and planning to pursue his dreams of a pro baseball career. He is convinced that if he hadn’t gone to Ostiguy, he’d still be using alcohol and drugs.

An estimated 1.3 million 12-to-17-year-olds have a substance abuse disorder. Youths between 12 and 19 account for nearly 12 percent of admissions to publicly funded rehab facilities, and about half of all students who return to traditional schools after treatment relapse within a year. Teens who relapse are less likely to stay in school.

Independence Academy in Brockton is one of five public “recovery high schools” in Massachusetts. (Courtesy of Massachusetts Recovery High Schools)

Proponents say recovery high schools such as Ostiguy greatly reduce the chances of a relapse and ultimately save taxpayers money by diverting a teenager from the criminal justice system.

As the nation struggles with an opioid-addiction epidemic, states increasingly have experimented with recovery high schools to help kids with drug and alcohol problems.

Twenty-seven public or charter recovery high schools operate in 11 states, including Texas, Minnesota and New Jersey. This month, Florida set up its first, in Jacksonville. In July, Pennsylvania Gov. Tom Wolf (D) signed a bill to allow public school students to attend the state’s lone recovery high school, which is private.

Other schools are slated to open soon in Chicago, Denver, Las Vegas, Washington and Colorado Springs, according to the Association of Recovery Schools (ARS).

“Recovery high schools can be a potential diversion for these kids, keeping them out of homeless shelters, foster care and the juvenile justice system,” said Kristen Harper, executive director of the ARS, a Denver-based nonprofit organization that provides support and accreditation services to the schools.

Getting a recovery school up and running is far from easy. And operating one is expensive. Recovery high schools typically spend $16,000 to $18,000 per student each year, according to the ARS. That’s compared with the national average of $10,700 for regular public schools. (Ostiguy spends about $32,000 per student, according to its principal, Roger Oser.)

Class sizes typically are small — the better to give students, many of whom have fallen behind academically, intensive support. Some schools have fewer than 15 students and none has more than 100, according to Andrew Finch, an associate professor at Vanderbilt University who has researched recovery schools for more than a decade.

Because recovery schools serve two functions — educating youth and providing therapy to them — they are complicated to operate. There’s considerable bureaucracy to navigate, from ensuring that curriculums meet state standards to finding a suitable location to securing transportation for kids who live far from the school.

And there are questions of who pays and who’s responsible for what.

Most public and charter recovery schools rely on a combination of public funding and private donations. Some charge a small fee to cover the costs of drug testing and support staff.

Because students often enter midyear, after completing rehab, and others may relapse, the size of the student body fluctuates, which can make it hard to set a budget. Schools treat relapse as part of the recovery process and usually readmit students when they return from treatment.

“We try to give kids as many chances as they need,” Oser said.

The recovery schools in Massachusetts were formed a decade ago as part of a plan to combat substance abuse. One out of 10 people age 12 and older in the state was dependent on alcohol or drugs. The state estimated that addiction cost $77 million each year in incarceration and $167 million in hospitalization.

Ostiguy is funded by the state’s education and public-health departments. It operates in collaboration with Action for Boston Community Development, a nonprofit human services organization; the Gavin Foundation, a substance abuse agency; and Boston Public Schools.

“A lot of people say, ‘I’d like to have a recovery high school in my state,’ ” Finch said. “And then they look into it. But it can be overwhelming. That’s where having a state legislator on their side can make things go smoother. It can get very political.”

Starts and stops

It took five years for New Jersey to open its first recovery high school, started by a community-based nonprofit organization, Prevention Links. Public school districts were leery, said Pamela Capaci, the organization’s executive director. They didn’t want a school that admitted only students with substance abuse issues, she said.

After many hiccups, Prevention Links partnered with a ­vocational-technical school district and opened the Raymond J. Lesniak Experience, Strength and Hope Recovery High School in Union Township. For now, classes are held in a building donated by a local college, Kean University.

The academic portion of the school is paid for with tax dollars, and the rest of the program is paid for through grants and fundraising. (The school’s annual budget is $450,000, Capaci said, but it should be twice that to adequately fund its activities.)

The school welcomed its first students — five of them — in 2015.

“We had so many learning curves. But with the heroin epidemic, it really made sense to bring this program to our state,” Capaci said. “We just jumped in, and I’m so glad we did.”

Last year, Gov. Chris Christie (R) signed a law to create three additional recovery high schools. But so far, no school districts have expressed interest, said state Sen. Raymond Lesniak (D), for whom the recovery school is named.

“The start-up obstacles are so high,” Lesniak said.

A further complication, he said, is that most superintendents are reluctant to refer students to schools outside their districts because that means losing some state funding.

He’d like to see federal and state laws changed so substance abuse is considered a disability. That way, he said, it would be easier to fund additional recovery high schools around the country.

Students with learning disabilities are protected under federal law, and school districts are required to provide special education services to these students. But they are not required to provide special services for students with a substance abuse disorder.

Without recovery schools to support them, teens who leave treatment go back to the environment where they got into trouble, Lesniak said.

“They relapse within days and hardly any of them ever graduate, and nothing good happens after that,” Lesniak said.

How successful the recovery schools are in helping students avoid relapse is hard to gauge. Vanderbilt’s Finch said there is little data. But preliminary research shows “quite positive results,” particularly with reducing marijuana use, said Paul Moberg, a research professor at the University of Wisconsin at Madison. (The two are collaborating on a national multiyear study of recovery schools.)

At Ostiguy, where 61 students were enrolled for the 2013-2014 school year, results were mixed. Sixteen of 21 seniors graduated. Eighteen students advanced to the next grade, six did not advance but remained enrolled, nine returned to their home school, four pursued a GED, and eight are no longer enrolled in any school.

Encountering defeats

Ostiguy High School is tucked away in a bland office building on a commercial strip in downtown Boston. A block or so away, in Boston Common, kids struggling with addiction sleep on park benches.

Inside Ostiguy, kids struggle to stay clean. The walls are plastered with inspirational quotes: “We may encounter many defeats but we must not be defeated.” “Words are free. It’s how you use them that may cost you.”

Students entering the school must be between 14 and 21, be sober at least 30 days and undergo a string of interviews to determine whether they’re ready to commit to recovery.

Students who don’t show up for class have to contend with Lyonel Traversiere, the school’s operations coordinator and all-around cheerleader and disciplinarian. Picking up the phone to check on students or taking a kid to a 12-step meeting is part of the job, he says.

Some kids can handle the discipline of showing up every day, staying sober and studying hard. Others can’t. But the doors are always open.

“For a lot of kids, this is their last option,” Traversiere said.