Sir doubt in rabin Karp

@0.50
sir it was said that

a^(p-2)=a^-1(modp)

and then how in next line it became

(a^(p-2))(modp)=a^-1

??? how did this happen??

take mod both side
(x%p)%p=x%p
so
it should be (a^(p-2))(modp)=a^-1(modp)