I suspect this refers to his degree – Master of Arts (Artium Magister), now more commonly abbreviated as M.A.
In the vital records you found this entry in, there is another John Rogers (d.1782), a Reverend (and apparently the father of your John Rogers), who also has A.M. after his name.
I could not find an image of the headstone for John Rogers d. 1827 – perhaps it doesn't survive. However, the headstone for John d. 1782 can be found on FindAGrave, where the letters A.M. are listed in a form consistent with a degree.

A next step to confirm this would be to identify where he studied, and see if any records survive regarding his education.
There is a John Rogers (recorded Johannes) who graduated with a Master's from Harvard University in 1767, which would be a good possibility. See Index of Harvard graduates in the classes of 1642-1772 (see page 73):
