RIO DE JANEIRO (AP) — The home Jose Nazare Braga built in the Rocinha shantytown is his life's work, an investment that grew from a shack to a three-story building over 30 years. A restaurant and a paper-goods store on the ground floor provide income, and his children, grandchildren and great-grandchildren live above.

The red-brick building is Braga's nest egg, his retirement home and an inheritance for his large family. But for decades, the property wasn't formally his, and he lived in fear of losing it all.

Now local officials and human rights groups are working to give legal title to tens of thousands of people like Braga, a process that increases their wealth and gives them greater access to credit, as well as peace of mind.

"I did this for my family, for my children," said the 70-year-old about obtaining the title to his property. For years he relied on a piece of paper given by the residents' association as his proof of ownership, and worried it wouldn't hold up in court if he was challenged.

"Now this is safe, secure," Braga said, sitting in his tiny, neat living room decorated with pictures of his family. "No one takes it away from us."

The programs so far are just beginning to tackle a widespread problem: A third of the people in Rio state, nearly 5 million people, don't have title to their homes, an uncertainty shared by most of the approximately 1 billion people who living in slums globally. Similar efforts are under way in many nations, where formalizing land tenure can give millions a secure hold on what is often a family's most valuable asset.

Homeowners have quickly discovered that their land can be used as collateral for loans and that property with a title fetches a higher price in the formal real estate market.

But there's also a downside. As the value of land goes up, it undermines the role of slums as the only well-located affordable housing available to low-income families in a city of booming real estate prices.

Land titling is one of an array of programs that have brought utilities, sewage connections and other benefits to Rio's slums in recent years. A push to control violence before the 2016 Olympics has seen permanent police posts installed in some of the favelas once controlled by the drug trade.

Thanks to such improvements, communities that began as informal settlements are starting to feel more like the city that surrounds them.

Giving families official title to their land is the key element in this transition, said Luiz Claudio Vieira, who manages the land titling program at the state's Institute of Land and Cartography.

"Bringing families into the formal city is a great benefit for Rio," Vieira said. "You integrate the community into the city, you put thousands of homes on the formal market, you take the residents out of the shadows, give them an address. This property starts to exist for legal and credit purposes."

Often, the titling process also means an area is officially mapped, giving residents an address to put on job applications or to use when opening a bank account.

Titling creates a healthier, safer urban environment, said Walter Borges Tavares, a public defender specializing in land tenure who provides legal counsel to the land agency. As slums are brought into the formal city, municipalities can enforce building codes and prevent the disordered construction that can degrade mountainside, destabilize slopes and cause landslides and deaths, he said.

The right to occupy unused land is guaranteed in Brazil's constitution. Legally, after five years of use, a resident can claim ownership. In reality, Brazil's sluggish court system often turned those five years into 20. There was also discrimination against shantytowns and those who lived there.

"There was this idea that if you regularized them, more people would come," Tavares said.

A state law approved earlier this year allows the land agency to register property formally owned by the state as a donation to the family occupying it, doing away with legal and bureaucratic hurdles. Using the law, the state of Rio will regularize about 10,000 properties this year and about 37,000 over the next four years.

Another new mechanism was pioneered by the nonprofit Bento Rubiao Foundation, which is working with the city to map out and title 8,000 properties in Rocinha, including that of Braga. The foundation is preparing the title claims for approximately 30,000 families statewide, said the organization's executive coordinator, Ricardo Gouvea.

The foundation recently won an unprecedented ruling that allows an entire community to get titled collectively. That case will help nearly 100 families receive their property papers all at once, and could be used to help other communities in the same way, Gouvea said.

"Brazil has always made it hard for the poor and blacks to own property," Gouvea said. "This is an important symbol. To have a right to the city, you start with a title to your land."

But as favelas are brought into the fabric of the formal city, slum dwellers are discovering some unwelcome changes to their communities.

Vidigal, a slum on a hill straddling two of Rio's most expensive zip codes, was occupied by a permanent police force in November, increasing security. Some of its properties already have titles and hundreds of residents are waiting for their papers. But foreigners and investors attracted by the incomparable ocean views and by the privileged neighborhoods surrounding the shantytown have also started snapping up land in Vidigal. A boutique hotel with a rooftop pool, designed by a renowned Brazilian architect, is under construction in the community where six months ago drug dealers conducted business with heavy weaponry.

Titling is happening very fast, without any education for poor residents or concern for preserving a community's positive characteristics, said Theresa Williamson, a city planner and founder of Catalytic Communities, an organization that works with favelas.

"These aren't simply neighborhoods; they're communities, and need to be considered as such," she said, proposing creation of community trust funds to keep housing affordable for those already living in the slums.

In Vidigal, rent has quadrupled over the past four years, and construction in the hyper-dense community is booming. Residents are torn between making money by selling to the highest bidder and staying amid the neighbors they have always known.

Sabrina Rosa's daughter will be the fourth generation of her family to grow up in the community's steep, narrow alleyways. Rosa owns, with title and all, the apartment where she lives. She also owns an untitled apartment at the top, with windows looking out over a vast expanse of the Atlantic Ocean.

If Rosa waits for the title, she'll be able to sell the place for more, much more than a neighbor might be able to afford. Though it seems the obvious choice, she's unsure.

"Vidigal is the Santa Teresa of the future," Rosa said, comparing the favela to a quaint, touristy Rio neighborhood. "The question is: What are the residents going to get from that process, and what are they going to lose? It's a change, and we don't know all the consequences. We have to find a way for it to work for everyone."