As reported in several experimental studies for Nd-Fe-B magnets, doping the small amount of transition elements, for example Ni, Cu, Zn, and Ga, into Nd-Fe-B magnets increases the coercivity. We calculated formation energies of transition-metal (TM) -doped Nd2Fe14B bulk and surface systems and the magnetic anisotropy <I>K</I><SUB>1</SUB> of Nd from first principles in order to understand which elements can improve the magnetic anisotropy <I>K</I><SUB>1</SUB> of Nd. Here, TM = Al, Si, Ti, V, Cr, Mn, Fe, Co, Ni, Cu, Zn, Ga, Ge. We used the computational code OpenMX. From the analysis of the formation energies in these systems, we find that the Fe 4c site at the surface is easily replaced by TM atoms. Especially in the surface systems, doping Ni, Cu, Zn, and Ga at the Fe 4c site improves <I>K</I><SUB>1</SUB> of Nd and the formation energies of these systems are lower than that of other systems.