If there are only two colors (let's say blue and red), here's what can happen:
sock #1 is blue
#2 is either blue or red. If blue, it matches #1 and you have a pair.
if red, go to #3
#3-either blue or red. If blue, matches #1. If red, matches #2.
OR sock #1 is red... then just reverse the colors. Basically, if you have three things that can only be in two groups, then even if two of them are different, the last one has to match one of them.