'a.m.' stands for 'ante meridiem' which is Latin for 'before noon'.
Similarly 'p.m.' (post meridiem) means 'after noon'.
So, strictly 12.00 noon can't be indicated by either a.m. or p.m. To stick with the Latin, it ought to be 12.00 m. (i.e. 12.00 meridiem)
However, there's a convention which accepts that, because 12.01 p.m., 12.02 p.m., etc, (through to 1259 p.m.) all indicate times in the hour commencing at noon, 12.00 noon may be indicated as 12.00 p.m., in order to maintain consistency. If this convention is accepted, it follows that 12.00 midnight, may be written as 12.00 a.m.
Chris