Seal the gap between the flue and metal flashing with a high-temperature caulk. Warning: Do not use spray foam for any of the joints near a vent pipe. Always use fire-resistant caulking. Now, you must form an insulation dam to prevent insulation from contacting the flue pipe.