There are $K$ bags of coins, each bag contains $m_k$ ($k=1,\dots,K$) coins, and thus we have $M:=\sum_{k=1}^K m_k$ coins in total.
Coins in the $k$-th bag satisfies $P(\text{H})=p_k$, $P(\text{T})=1-p_k$ (here, H and T stands for head and tail).
The question is, what is the probability of getting $N$ heads when we toss these $M$ coins?
Collection of my thoughts:
We have $k=1,\dots,K$ of bags, and there are in total $\frac{(K+N)!}{K!N!}$ ways of getting $N$ heads from different bags.
For $k$-th bag, suppose we have $n_k$ heads. Then, there are $\frac{(K-1+N-n_k)!}{(K-1)!(N-n_k)!}$ ways of getting $N-n_k$ from other bags.
For $k$-th bag, the probability of getting $n_k$ heads is${m_k \choose n_k} p_k^{n_k}(1-p_k)^{m_k-n_k}$.
etc., but I am not convinced or I cannot get it right.