For many authors, a first book is written in a cozy office nook. For others, it’s written during rush-hour commuter-train trips or at the kitchen table after the kids have gone to bed. Indie author M.R. Mathias crafted his debut fantasy novel in a decidedly unusual place. “I wrote the Wardstone Trilogy in a Texas prison, where I was doing two years for drug possession,” he says. “I was a needle junkie.”

Mathias loved to write fiction in high school, but after graduating he started playing in a band and focusing more on writing song lyrics. He says he embraced the proverbial rock-and-roll lifestyle a little too fully. “I ended up living out of my truck and in cheap motels, stealing for drug money,” he says.

Though getting arrested in 2007 was undoubtedly rock bottom for Mathias, it ended up saving him from an uncertain—though certainly destructive—future. His first week in prison was pretty rocky: he ended up in a fistfight and was sent to a solitary cell.

But Mathias soon saw a silver lining. For one hour a day, he and his neighboring inmates were allowed out. “We could trade books through the gap under the door,” he says. “I remember having to rip the spine of a Terry Brooks paperback in half longways because, even opened and spread, it was still too thick to slide under. There were books coming to people through the mail, and they would circulate. One day, after reading something about Raymond E. Feist just putting pen to paper and ending up with his masterpiece, Magician, I was struck with inspiration.”

Mathias figured that he had a year and nine months to devote himself to writing. “So I set a goal of writing 10 pages, while also reading about 300 pages, a day,” he says.

Mathias’s writing environment came with a very unique set of challenges. He says he wrote in longhand on notebook paper “with crappy ballpoint pens.” He also had to work around the vagaries of his neighbors. “Some guys were so rowdy and insistent on hassling the staff that they would flood their cell, which would, in turn, flood every cell,” Mathias says. That meant he had to watch where he placed his inky manuscripts.

It’s the little conveniences that matter, Mathias learned. “The disadvantages were obvious: no spell-check, no cut and paste, no way to search for a scene or character,” he says. “The worst was no digital thesaurus or dictionary—two tools I could not live without these days.”

And, yet, Mathias counts his two years in a solitary cell as among his most fruitful and empowering. “It was one of the absolute best things to ever happen to me,” he says.

Though Mathias didn’t directly integrate material from his time in jail into his work, certain experiences inevitably seeped into the writing. In the Wardstone Trilogy, “the overarching story line concerns the ignorance of racism and prejudice, which was inspired by all the racism and gang violence I witnessed,” he says.

After he was released from prison in 2009, Mathias ended up caring for his grandmother, who had Alzheimer’s. It allowed him the time he needed to recuperate and revisit his writing in a decidedly different environment. He also developed a new skill: “I started learning to type.”

Mathias published the first book in the Wardstone Trilogy, The Sword and the Dragon, in 2010. He wrote and published The Royal Dragoneers (book one of the Dragoneer Saga) shortly after that. His other series include the Dragon Racers, Fantastica, and Legend of Vanx Malic. Writing under pseudonyms, he has published The Butcher’s Boy: The Ballad of Billy Badass, the children’s series the Awesome Opossum, and a standalone picture book, The Amazing Book of No.

Mathias says his book sales through Amazon have totaled over $1 million, and he has more than 200,000 Twitter followers. He adds that he has another “huge trilogy” in him and is looking for a publisher.

These days, Mathias’s favorite place to write is on the boat slip he owns with his wife on Lake Texoma, Okla. “When the story starts flowing, it is a wonderful place to write,” he says. “But only during the week: the weekends are hectic with fishermen and swimmers.”

When it is too cold for the lake, Mathias writes at a desk he built into a bay window nook off of his bedroom. “The house is modest, but it sits on five acres of Oklahoma woodland,” he says. “On any given day, I might see a flock of wild turkeys, deer, hawks, owls, coyotes, or even a bobcat right outside the window. We also have hummingbirds, cardinals, blue jays, and a half dozen woodpeckers that frequent the bird feeder. I guess I’m lucky.”