New method for synthesis of metal carbides, nitrides and carbonitrides