An interesting question! Although many people have adopted a standard usage of calling midday 12pm and midnight 12 am, this choice is actually quite arbitrary.
In fact, the correct answer is 'neither'. As a speaker of a Latin language, you'll be aware that 'am' and 'pm' stand for Latin phrases, meaning, respectively 'before noon' and 'after noon'. So, to say either 12 am or 12 pm is actually meaningless.
The style advice is to avoid either term. Say 12 noon, 12 midday, or 12 midnight. Or just 12.00. Or 24.00.