Make an underground country and only accept migrants if initially invited to migrate in. Only useful and competent people will be invited in. Immediate deportation if you commit a major crime.
Limit national population, no religion, no separation of science to public, stay globally neutral, ignore the outside world.