Pentax introduced the K series cameras to replace the Spotmatic series. The Spotmatics used the m42 lens screw mount, which had been extremely popular for many years, but was now losing sales to bayonet mount lenses that were faster and easier to install. Pentax saw the writing on the wall, so had to make their own bayonet lens mount, called the K mount, in order to stay competitive in the camera market.
The K series cameras introduced the K mount, but were similar in size to the previous Spotmatics. There were different Spotmatic models at different price points. The Spotmatic F (SPF) was the top of the line manual exposure model, and the ES II was the electronic model with auto exposure. The KX replaced the Spotmatic F as the top end manual exposure model. The K2 replaced the ES II as the auto exposure electronic model. The K2 was the most expensive camera, due to the electronics, as was the previous ES II.
The other K mount cameras were just stripped down versions of the KX, to sell at lower price points. The K1000 was the "cheapo" basic "no frills" model. The KM was the middle model that had a few more features than the K1000, but not as many as the KX. The K1000 became extremely popular due to it's low price. It had all the features that were needed by most users on a budget.
The Olympus OM-1 was already in the marketplace when Pentax released the K series cameras, so they were still under pressure to introduce smaller cameras to compete with the OM-1. Pentax did that by introducing the M series cameras a year or two later. The MX became the top of the line manual exposure camera, and the ME became the auto exposure model. The K series was quickly ended, except for the K1000, that remained as the low budget option for many years.
The Pentax KM and KX models are not that common, since they weren't in production very long. The K2 is a bit more common since it was a bit more "high end" than the ME, and was also available with a motor drive for the K2 DMD. Pentax resolved this by introducing the LX as a true professional grade compact camera.