It might help you to study a few specific cases.
For example, $a = 10$, $p = 7$. We see that $10^6 = 1000000$ and 999999 divided by 7 is 142857.
But let's work through this example using smaller numbers. Obviously $10^2 = 100$. But 98 is a multiple of 7, which means that $10^2 \equiv 2$ $\pmod 7$. And 10 itself is $3 \pmod 7$, so we can calculate $10^3 \equiv ?$ $\pmod 7$ as $2 \times 3 = 6$. And then $10^4 \equiv 6 \times 3 \equiv 4 \pmod 7$. Next we have $10^5 \equiv 4 \times 3 \equiv 5 \pmod 7$.
Lastly, $10^6 \equiv 5 \times 3 \equiv 1 \pmod 7$,
which we had already confirmed. I chose this example because $10^n$ modulo 7 takes on every value from 0 to 6 except 0. That's not always the case, but it helps to show which values can't be taken on.
Now consider instead $p = 14$, which is clearly not prime, and $a$ the same as before. You might be aware of the fact that 14 is not a Fermat pseudoprime. But much more importantly in this example, $\gcd(10, 14) = 2$, so we will see that $10^{13} \not\equiv 1 \pmod{14}$.
Then we see that $10 \equiv 10 \pmod{14}$, which is obvious but needs to be said, because $10^2 \equiv 2 \pmod{14}$ just the same as modulo 7. Then $10^3 \equiv 6 \pmod{14}$, $10^4 \equiv 4 \pmod{14}$, $10^5 \equiv 12 \pmod{14}$, $10^6 \equiv 8 \pmod{14}$, $10^7 \equiv 10 \pmod{14}$, $10^8 \equiv 2 \pmod{14}$... whoa, we're back to 2.
The common divisor between 10 and 14 is 2, which means that odd numbers (coprime to 2) can't occur in $10^n \equiv ? \pmod{14}$.
I hope this helps you understand. You might also want to work through examples where $p$ is composite but nonetheless coprime to $a$. Probably hold off on numbers like 341, 561 for now, though.