First-principles study of doped Si and Ge nanowires