Controlled insertion and retrieval of atoms coupled to a high-finesse optical resonator