The base of the pyramid has $n$ edges, so also has $n$ vertices around the base. This then means that there are $n$ edges around the base (in red) of the pyramid and $n$ that meet at the apex (in black).
Therefore there are $2n$ edges in total.
There are also $n$ faces that meet at the apex of the pyramid, and one more for the base, so a total of $n+1$ faces.
Therefore the difference is $2n - (n+1) = n-1$.