Congruence condition for -1 to be a quadratic residue