inverse modulo for non primes

is it possible to find the solution of following:

9^(-1)%M

ie inverse of 9 modulo M

where 2<=M<=10^9 it may not be a prime and gcd(9,M) may not be 1

if not possible to find such a solution is there any method to solve:

((10^n-1)/9)%M

1<=n<=10^16

take modulo M*9 instead of M and after that divide your answer by 9.