Vacancy-mediated mechanism of nitrogen substitution in carbon nanotubes