We shall prove the statement using strong induction.
Suppose the existence of such a subset $\forall n\le k$. We wish to prove the existence of such a subset when $n=k+1$.
If $m=k+1$, then $A=\{1,2,...,k+1\}$, and letting $B=A$ clearly works.
Otherwise, $m\le k$. If $A\subseteq \{1,2,...,k\}$, we can construct B directly from our supposition (the rightmost inequality becomes weaker for $n=k+1$ as compared to $n\le k$, and the leftmost inequality is equivalent).
Else, $(k+1)\in A$.
If $M-k-1\ge 1$, let $A' = A\setminus\{a+1\}$. Applying our induction hypothesis onto $A'$, we guarantee the existence of some set $C$ such that
$$0 \leq \sum_{c\in C} c - (M-k-1) \leq k-m+1.$$
Then, simply letting $B=C+\{k+1\}$ works, as $\sum_{b\in B} b - M = \sum_{c\in C} c + (k+1) - M = \sum_{c\in C} c - (M-k-1)$.
Otherwise, $M\le k+1$. Again, let $A' = A\setminus\{a+1\}$. Applying our induction hypothesis onto $A'$, we guarantee the existence of some set $C$ such that
$$0 \leq \sum_{c\in C} c - M \leq k-m+1.$$
Then letting $B=C$ works.
It remains to show the base case, when $n=1$. This is rather easy.