Two numbers are relative prime if their greatest common divisor is $1$, that is $gcd(n,a)$. We can also find no of elements that are relative prime to given number by Euler function.
How can I find a number suppose '$a$' that is relative prime to my given number let's say '$n$' and is smaller than '$n$'? Ideally I want smallest number that is relative prime to $n$ except $1$.
Primes are : $2,3,5,7,\ldots$. You can check divisibility of $n$ by $2$ if it's not divisible then $a=2$ if it is then try $3,5$ etc. Or you can find the product of primes that compose $n$ and pick the smallest prime not included. (this is if you don't want the number $1$)