In an isosceles triangle, the lengths of the base and the median to one leg are equal. Find the cosine of the vertex angle.