Noah realized that, as the father of all future humanity, he was playing the role of Adam in the new, post-Flood world. He therefore tried to rectify Adam and Eve’s mistake of misusing wine (the fruit of the Tree of Knowledge) to achieve self-awareness. Instead, he hoped to lose himself in Divine joy by becoming intoxicated. But because this selflessness was artificial, it backfired, and Noah instead exposed himself indecently. Hearing of this, Noah’s sons covered him up, but whereas his youngest son, Ham, focused on his indecency, his older sons, Shem and Japheth, focused on the task of restoring their father’s modesty.
Human Mirrors
וַיֵּלְכוּ אֲחֹרַנִּית וַיְכַסּוּ אֵת עֶרְוַת אֲבִיהֶם וגו': (בראשית ט:כג)
[Shem and Japheth] walked backwards and covered their father’s nakedness. Genesis 9:23

The Ba’al Shem Tov taught that the people we encounter in our lives are our mirrors: If we see evil in them, we are really seeing a reflection of the evil within us. Since we are generally blind to our own faults, G‑d arranges for us to notice them in someone else, expecting us to take the cue and recognize that we possess these same faults so we can correct them in ourselves.

Thus, since Shem and Japheth did not share their father Noah’s weakness, they did not focus on it; instead, they focused on how they could help him. In contrast, Ham did share his father’s weakness; therefore, he focused on his father’s shame rather than how he could be of help.1