"Ladies and gentleman" is the most common and accepted form of addressing an assembly of men and women, and ladies are shown respect by addressing them first.
But in the earlier times, say some four hundres years ago, when the formal official or court letters started getting their present form, there were practically no women holding the post of an officer or were proprietress of any business. Thus the salutations started with "Dear Sir". And as the women participation in Office and business started expanding, so did the salutations to them in office correspondence and it was obvious that a typist/letter write would use "Dear Sir/Madam" if it was not known to him that the recipient was a man or a woman. Thus it is more due to custom that Sir comes first than Madam in formal official letters.
- For Teachers