The key point is that if $\rm\ a^n = 1\ $ then exponents on $\rm\ a\ $ may be reduced mod $\rm\,n,\,$ viz.
Hint $\rm\quad a^n = 1\ \,\Rightarrow\,\ a^i = a^j\ \ { if} \ \ i\equiv j\,\ (mod\ n)\:$
Proof $\rm\ \ i = j\!+\!nk\:$ $\Rightarrow$ $\rm\:a^i = a^{j+nk} = a^j (a^n)^k = a^j 1^k = a^j\ \ $ QED
Yours is the special case $\rm\:0\ne a\in \Bbb Z/p,\:$ so $\rm\:a^{p-1}\! = 1,\:$ so exponents may be reduced mod $\rm\:p\!-\!1.$
Remark $\ $ You should check that proof works ok if $\rm\,k < 0\:$ (hint: $\rm\: a^n = 1\:\Rightarrow\: a\,$ is invertible, so negative powers of $\rm\,a\,$ are well-defined). The innate structure will become clearer if you study university algebra, where you will learn about cyclic groups, orders of elements, and order ideals, and modules.