Well, I'm of the impression that pain is simply a higher form of pleasure, in some cases. Take, for example, the fact that humans naturally like to be cooled down when too warm. Lovely, refreshing and cold. Yet if it is too cold, it can be dangerous, therefore a higher form of the pleasure before it crossed the line.
Another example would be the other extreme, heat. Warm, cosy fires, lovely. But, too hot and everything turns to ashes. Ergo, a higher form of the pleasure felt when only warm.
😆 It works perfectly in my head. And it's my excuse for erotic sex.