Segmentation fault is a memory error which means you've gone beyond the memory allocated to the program by the OS. In more concrete terms, you've gone far beyond the bounds of an array. This happens on line 32 for you.
At the start of your program, you declared marked to have M elements or 1,000,000. When you input 1,234,567, like 32 tries to access the 1237567th element. This goes significantly beyond the bounds of your array, causing your segmentation fault.