You can also apply the Zorn Lemma here. Consider the family of ideals $F$ such that $Q\in F$ if and only if $X\subset Q\subset P$, with the order $Q\leq Q'$ if $Q'\subset Q$.
Let $(Q_i)_{i\in I}$ a total ordered family of $F$, $Q=\cap_{i\in I}Q_i$ is a sup of the family. To see this we have just to show that $Q$ is a prime ideal. Let $a,b\in R$ such that $ab\in Q$. Suppose that for every $i_0$, there exists $i,j\geq i_0$ such that $a$ is not in $Q_i$ and $b$ is not in $Q_j$. We deduce that $b\in Q_i$ and $a\in Q_j$ since $Q_i,Q_j$ are prime ideals. Since $I$ is totally ordered, we can assume that $i\leq j$ this is equivalent to $Q_j\subset Q_i$ and $a\in Q_j\subset Q_i$. Contradiction.
We deduce that there exists $i_0$ such that for every $i\geq i_0$, $a\in Q_i$ or $b\in Q_j$, this implies that $a\in\cap_{i\in I} Q_i$ or $b\in \cap_{i\in I}Q_i$. So $Q$ is prime.
There exists a maximal element for this relation which is the minimal $M$.