You have to unscrew the ring that says SMC PENTAX-M 1:2.8 40mm, using some sort of friction tool, rubber crutch tip, etc. Then you'll see three screws in cutouts and three more screws holding on the filter ring. Remove the filter ring screws and the filter ring. There's three more screws on the outer edge which hold the focus ring to the focusing helix. It looks something like this M50/1.7, and the screws you want are marked with red arrows:
Put the lens on a camera. Turn the focus ring to the infinity stop. Loosen those three screws. Now you can turn the focus ring back a bit, maybe the 10 meter mark, without changing the focus of the lens. Tighten one screw and see if you can focus to infinity now. After some trial and error, you should be able to focus to infinity again. Tighten all the screws, reinstall the filter ring, put the trim ring back on and you're done.
Since you have a film camera with a split prism fiocus screen, finding infinity can be a little easier with that camera because the viewfinder's bigger and brighter.