Brazil wins final minute over Japan to reach knockout stage