The first step in the long way back would be to park the spacecraft in Martian orbit in order to then enter the transfer orbit to return to earth. As it has been seen, this is relatively simple to calculate and the velocity to enter a particular Martian orbit can be estimated with the same expression used for terrestrial orbit:
V= [G . Mm / (R+r)]^1/2
where Mm is the mass of Mars, R the radius of Mars and r the height of the particular orbit required.