Three men stand in a line. Each has a hat placed on their head — either black or white — from a set of three black and two white hats. Each man can see the hats in front of him but not his own. The last man says he does not know his hat color. The middle man then also says he does not know. The first man, who sees no hats, says he knows his hat color. How?