And it came to pass at the end of two years (Genesis 41:1)
Every affliction to befall man has a set time to end; as it is written, "An
end He set to darkness, and every limit He investigates" (Job 28:3). This
is said regarding Joseph, who was ten years in prison but G-d investigated
and saw that it is necessary for him to be imprisoned for another two years...
"In every sorrow there is profit" (Proverbs 14:23). This, too, is said
in regard to Joseph, who suffered in prison and then profited from it [in
becoming] ruler over Egypt.
(Midrash Tanchuma)
As he interpreted to us, so it was (41:13)
Said Rabbi Banaah: There were 24 interpreters of dreams in
Jerusalem. Once I had a dream and went around to all of them and they
all gave different interpretations, and all were fulfilled, confirming
that which is said, "All dreams follow the mouth."