You would have to revalidate your medical degree. That is made through an exam (quite hard, actually, only a small percentage of applicants are approved) called "Revalida". After being approved on the exam, you would have to do the residency exam for the program you want. Each program has its own test, that generally includes a theoretical test and a practical one. There's a curriculum factor on getting accepeted on residencies, but the good news is that if you perform well on the exam, you're in (CV usually counts for only 10% of the score). You would also need to speak fluent Portuguese. Both tests (revalida and residency exams) can be made as many times as you want, so you can retake them if you fail). In Brazil there're many prep schools that help you to study for residency exams, but keep in mind they're very competitive.