If (x^2-x-2) is HCF of the polynomials (x-2)(2x^2+ax+1) and (x+1)(3x^2+bx+2), find the value of a.