Lemma: It's the set of those squarefree $n$ with the following property: if the prime $p$ divides $n$, then so does $p-1$.
Proof: If $p$ is some prime, $p^2 \nmid p^{n+1}-p$, thus $p^2 \nmid n$.
If $p|n$, then we take a primitive root $a \mod p$ and get that $a^{n} \equiv 1 \mod p$, thus $(p-1)|n$ by the order-lemma.
Conversely, if $n$ fulfills that properties and $p|n=(p-1)q$, then $a^{n+1} = a^{(p-1)q+1} \equiv a \mod p$ (even if $p|a$).
Claim: all such numbers $n$ are $1,2,6,42,1806$.
Proof: Testing these numbers to work using the lemma is easy, so we just show there are no others.
Assume there are more than we claim to be and let $n=p_1 p_2 ... p_k$ with $p_1 < p_2 < ... < p_k$ be the smallest exception. Then the number $n^\prime=p_1 p_2 ... p_{k-1}$ still has the property by the lemma (all requirements are fulfilled again) and is in $M$.
Additionally, $p_k-1|n^\prime$, leaving us to check that all numbers $d+1 $ with $d|1806=2\cdot 3 \cdot 7 \cdot 43$ and $d \not\in M$ are not prime.
This is left to the reader