Use Euclid’s algorithm and backwards substitution to determine the

multiplicative inverse of 27 in Z40 .
I've worked out;
40 = 1*27 + 13
27 = 2*13 + 1
Then rearranged to make the remainders the subject.
1 = 27-2*13
1 = 2(40-1*27)

Bit confused where to go from here...