The invention relates to compounds of formula I wherein A1, A2, A3, B, R1, R2, R3 and R4 are as defined in the description and in the claims, as well as physiologically acceptable salts thereof. These compounds inhibit PDE10A and can be used as medicaments.