there were several sections called "M" basically MI5 and MI6 deal with diffrent types of Military Intelligence
MI5 (I think ) deal with home ie UK issues and MI6 deal with overseas issues it may be vice verca but that's the jist of it.
If I remember correctly the MI (military intelligence) sections/departments went up to 42. These gradually became disbanded or amalgamated some time after the second world war. Each department had their own speciality roles which became obsolete without the war. MI5 is for home security and MI6 is for overseas. Hope this helps.