First-principles study of substitutional metal impurities in graphene: structural, electronic and magnetic properties