Electronic structure and metal-insulator transitions in Ti and V oxides