Inserting pages in the middle of a threaded document is tricky. The best way I found without mayor hassle is using Rorohiko's free plugin: https://www.rorohiko.com/wordpress/indesign-downloads/textstitch/. Read the instructions carefully. Regarding the script, this might help: http://indesignsecrets.com/how-to-install-a-script-in-indesign-that-you-found-in-a-forum-o r-blog-post.php. But it seems you already did it, so it might be something else. What is the script?
There's another possibility here, too, and that's how/where you clicked the loaded cursor and what was already on page M + 1, M + 2 and beyond.
Ideally, you would have held down the shift key when you placed the text initially, but the same possible problems arise no matter when you start auto-flowing if you have master text frames. You mentioned you clicked on the upper left corner of page M+1. Did it have a master page placeholder text frame? If so you would have wanted to use that frame, and in order to do so you would need to click INSIDE the frame area, NOT on any guides (watch the loaded cursor and be sure it is surrounded by parentheses).
Clicking on a guide would ignore the master frame and would continue to autoflow text onto following pages adding new frames on top of any master text frames regardless if they already were overridden and had text in them or were empty. Similarly, if pages M+1and M+2 through N share the same master page and you attempt to autoflow, ID is going to flow the text from M+1 to M+2 and beyond and add new frames UNLESS the text on pages M+2 through N and beyond is in the same thread already (which it cannot be if you have overset text on Page M). Using a different master page should alleviate that, causing ID to create new pages based on the second master rather than flowing over existing pages.
As far as the script problem, it could be the script is written in AppleScript, and that won't work on PC.
The script turned out to be fine. The correct extension was .jsx. The problem was that somewhere in the process of copy/pasting it from the Web to Notepad, something decided the straight quotes really should be curly quotes. Which normally would be correct (though not the way it ended up being implemented here), but in the case of a script obviously is not. Even my rank amateur *** knows enough about coding to know that. Once I put the quotes back in order, everything worked out fine.
There are no text frames in the main body of my master pages (there are for running header elements, but surely that's not relevant here). I don't remember what the problem with them was, but they caused problems with the way my workflow worked in the early days of my current project. I've just been placing or (and this usually seems to be preferable in practise) creating a text frame and pasting, then using the out port -> shift+click method. This was fine until I needed to do it in the middle of a document.
Without a master thread, and a single master page applied, the normal behavior for autoflow is exactly what you experienced. Smart Text Reflow might have worked better.
Glad the script worked out for you.