You can think about the problem in either of two ways. One is the way that you seem to have in mind in your comment: add up the possibilities for every possible boy-girl split, from $4$ boys and $P-4$ girls to $P-1$ boys and $1$ girl. (I’m assuming that $N\ge 4$, $M\ge 1$, and $P\ge 5$, so that there is at least one possible combination.) If you do this, you have to evaluate
$\sum_{n=4}^{P-1}\binom{N}n\binom{M}{P-n}\;:\tag{1}$
the number of ways of picking $n$ boys out of $N$ is $\binom{N}n$, and the number of ways of picking $P-n$ girls out of $M$ is $\binom{M}{P-n}$, so the number of ways of forming a combination with $n$ boys and $P-n$ girls is $\binom{N}n\binom{M}{P-n}$, and you need to sum these over all possible values of $n$.
If you’re writing a computer program to solve the problem, this is entirely feasible, but it would be rather painful to do by hand if $P$ were very large.
The other possibility is to count the unacceptable combinations and subtract that number from the total. In other words, if there are $u$ unacceptable combinations, calculate $\binom{N+M}P-u\;.\tag{2}$ The advantage to this is that if $P$ is at all large, there are fewer ways to form unacceptable combinations than to form acceptable ones:
- you could have $P$ boys and no girls, or
- $P$ girls and no boys, or
- $P-1$ girls and $1$ boy, or
- $P-2$ girls and $2$ boys, or
- $P-3$ girls and $3$ boys.
That’s a mere five boy-girl splits to worry about, and instead of the $P-4$ terms of the sum in $(1)$, you’ll have only five terms (and the one subtraction in $(2)$). Thus, as soon a $P$ gets up to $10$ or so you’re better off using the second method.