If I get question correctly you can solve this in O(n) time.
- find two same elements using "hash" of size N
 - set one of this elements to 0.
 - make sum of elements and substract from calculated sum and you have the missing/replaced element (sum of elements is (2M+N-1)*(N)/2
 
EDIT:
Explanation of 1. point (find two same elements using "hash" of size N)
- If you do not not know M find it (finding smallest element is O(n) , just one loop)
 - Alocate array h of size N and set elements to 0 (can be type BOOL )
 - go trough table and check 1 at apropriate location off h
 - if it is 1 then you have colission, else set 1.
 
code for last part:
for(i=0;i<N;i++)
{
    if(h[a[i]-M] == 1) return i;
    h[a[i]-M] == 1;
}