The smallest positive integral value of $a$ for which the greater root of the equation $x^2-(a^2+a+1)x+a(a^2+1)=0$ lies between the roots of the equation $x^2-a^2x-2(a^2-2)=0$ is: