The Spanish for “foam”, espuma, comes from the Latin for the same: spuma. And this Latin comes from the Proto-Indo-European root *(s)poi-moi from which we also get the English… foam.
How so? Because the PIE root p- very consistently became an f- as it evolved into German then English, but this transformation never happened when it became Latin and then Spanish. Note words like foot/pie and father/padre.
Thus the f-m of foam maps to the (s)-p-m of espuma very clearly!