The basic structure of our current road numbering system was established before the existence of motorways. Six main highways, radiating out from London, were numbered A1 to A6 (reading clockwise). All roads to the 'clockwise' side of the A1 were given numbers beginning with 1. The most important A roads were given two digit numbers, with 3- and 4-digit numbers being used for more minor A & B roads. Similar policies were used for roads to the 'clockwise' side of the A2, A3, etc.
The same system was used for Scotland, with the principal roads, radiating out from Edinburgh, being numbered A7, A8 and A9 (and with more minor roads being numbered in accordance with their positions relative to these three roads).
Motorways are numbered, as far as is possible, in a way which fits in with the system for A and B roads. The M1 probably received its name because it runs in roughly the same direction as the A1 (and not because it was the first motorway built). Similarly, the M2 follows roughly the same route as the A2, etc. (The obvious exception to this rule is the M5. Presumably it was decided that no motorway would follow the route of the A5, so there was a 'spare' number for a principal motorway in England).
Additional motorways were numbered in accordance with the 'clockwise' rule (e.g. the M20 and M23 both lie on the 'clockwise' side of the M2).
In Scotland, motorways were numbered M8 and M9 in accordance with the policies explained above. However, unless the name 'M7' is used as a 'spare' name (in the same way which 'M5' has been), it's unlikely that there will ever be an M7 unless it's decided that a motorway is required between Edinburgh and Carlisle.
Chris