Answer
$P=2mg\space tan\theta$
Work Step by Step
We can determine the largest horizontal force $P$ as follows:
For Block $A$
$\Sigma F_y=0$
$\implies Ncos\theta-mg=0$
$\implies Ncos\theta=mg~~~$eq(1)
and $\Sigma F_x=ma$
$\implies Nsin\theta=ma~~~$eq(2)
Dividing eq(2) by eq(1), we obtain:
$a=gtan\theta$
Now for block $B$
$\Sigma F_x=ma$
$\implies P-Nsin\theta=ma$
$\implies P-mgtan\theta=mgtan\theta$
$\implies P=2mgtan\theta$