They are abbreviations of Latin terms. A. M. is Ante Meridiem where Ante means "BEFORE" and "Meridiem" means "MIDDAY" or "NOON". P. M. Refers to Post Meridiem where "POST" means "AFTER" and "Meridiem" still refers to "MIDDAY" or "NOON".
A. M. stands for the Latin words "Ante Meridiem" which translates into before noon. P. M. is for the Latin words "Post Meridiem" which means after noon.