Suppression of longitudinal losses in a gas-dynamic trap by using an ambipolar mirror