Where did the Ming armies retreat to?