San Marino, a nation of about 35,000 people completely surrounded by the Italian state, traces its origins to the fourth century.