POWPOW2 spoj hard problem

How a ^phi(m)=1? I mean [a^(p-1)]%p=1 so how a^phi(m)=a^p-1?