Terrorists have safe havens in Pakistan, Afghanistan: US