Ancient China developed farming of crops like millet, soybeans, and rice as early as 5000 BCE. From 1700 BCE to 256 BCE, China was dominated by the Shang and Zhou Dynasties. The Yellow River provided irrigation for farming but also caused floods. Society was organized around farming villages along the river, with the rich living in cities and the poor in rural areas. Political organization centered the king and nobility in cities, with outer districts for workers and peasants in the country. Religion focused on nature spirits and ancestors. Writing developed with over 1,000 characters needed to be barely literate. In 1027 BCE, the Zhou Dynasty overthrew the Shang using the concept of the Mandate of Heaven.