The van der Waals equation for a real gas is:
$$RT =\left(p+\frac{a}{V_\mathrm{m}^2}\right)(V_\mathrm{m}-b)$$
We have understood this formula by saying that $a$ is the term which is for force of attraction between the gas molecules and thus the pressure of a real gas will be less than that of an ideal gas.
Therefore some factor must be added to the pressure of a real gas to make it equal to ideal gas pressure so that it can be used in $p_\mathrm{ideal}V_{\mathrm{ideal}}= nRT$.
Also, if we see the compressibility factor graph , suppose for $\ce{N2}$:
(Source: TutorVista)
If $Z < 1$, then attractive forces are dominating. We see that after a particular temperature, the value of $Z$ becomes greater than $1$, implying that the repulsion forces are dominating in $\ce{N2}$.
Now, since repulsive force dominates, the pressure of the real gas will increase and be greater than that in ideal case.
To find the $p_{\mathrm{ideal}}$ now, we will need to deduct some value from the $p$ of real gas, which means $a$ should be negative. However, this is not so as $a$ can never be negative.
No value can ever be deducted from $p$ in the van der Waals equation.
Then how does the van der Waals equation still work and give the correct data?