Does taking a long time to graduate impact my Ms/PhD admission? I need some advice on my career. I study in Brazil and I'm one year away from obtaining my bachelor in Mathematics. Here the duration is 4 years.

In 2016 I had to start working two jobs (unrelated to Math) to help my family and that made my 4-year journey into a 5 and a half years journey in which during the process I've failed a couple of classes due to attendance. I was able to quit the job this month and from now on I'll be able to focus only on my studies. 

My question: is there still a chance for me to work on my Master's, Doctorate and so on? And also how much does the fact that it took me 5 and a half years counts? Despite not being able to attend the classes, I consider myself a good student and I know for sure I'm dedicated.
As a rule of thumb, the time you took wont matter, but the failing grade will.

However, if your goal is to get into a masters course in Brazil, many of them won't look at your undergraduate marks (I've served on graduate committees on two top brazilian math departments).

In these cases, you can be admitted by doing well on an admitting summer course, or on an admission exam (many of them nowadays use the Extramuros examination, or a local exam).

Even for institutions that will judge your undergraduate marks, it's not uncommon that a student with a failing mark get accepted. Usually they would indicate in their statement why they failed and how they did well on this course on the next time. The fact that you had to work is enough justification, if that's a localized problem and you have strong marks otherwise.

After doing well in your masters, your undergraduate marks will have a negligible impact on your PhD admission.