I'm confused. The title asks about K and M
mount lenses. K-mount is Pentax K mount, as all Pentax DSLRs have it (and in the past various film SLRs as well). M-mount usually refers to Leica M which is made for rangefinders and is, as far as I know, completely incompatible with Pentax K. More info on M mount here:
https://en.wikipedia.org/wiki/Leica_M-mount
OR
Maybe you meant Pentax lenses which were called M series? These M series lenses are K-mount. They came after the previous series, which was not really officially labelled, but is commonly called K-series because it was the first K-mount series. All Pentax K and Pentax M lenses will fit on your Pentax cameras. You can see the index of lenses here:
Pentax Lenses - Pentax Lens Reviews & Lens Database
m42 was the old screw mount, which was replaced by K-mount bayonet system, which started with K and later M and later A series. The series would evolve over time. For example, A series is the first with auto-aperture (where you can select aperture through camera instead of twisting the aperture ring by hand on the lens). F series was the first with autofocus, and so on. Each series also has its own style of appearance. M series is known for rather tiny, metal lenses. K series is known for slightly bigger lenses, but many had really great image quality. Note that some optical lens designs went through the series - for example M 50mm f1.7, A 50mm f1.7, F 50mm f1.7, FA 50mm f1.7 and DA 50mm f1.8 share this lineage - they have very similar, if not the same, optical design. But some lenses only made an appearance for a short time, within one series.
So I don't know what exactly the question was. Leica M mount lenses are completely different. I think the Pentax FA 43mm limited was also produced in Leica M mount for a while. But this is not really relevant unless you have a camera with Leica M mount