Show that every principal ideal domain is a unique factorisation domain I have to show that every principal ideal domain is a unique factorisation domain.

I can show that every non invertible element that is not equal to $0$ can be written as product of irreducible elements.

However, I have troubles showing that if 

$$p_1 \dots p_n = q_1 \dots q_m$$ where $q_i, p_i$ are irreducibles elements, then $n = m$ (I already showed that every $p_j = u_iq_i$ with $u_i$ invertible) 

Any hints?
You know that in a PID a element is irreducible if and only if it is prime. Then, if $p_1$ on the left divides $q_1 \cdot \ldots \cdot q_m$ then it must divide one of this factors, lets say $q_i$. But $q_i$ is irreducible, thus

$$ p_1 = uq_i $$

where $u$ is invertible. By induction, you can then show that $m=n$

after $k$ times, if $m$ is less than $k$ (which happen only when $m&lt;n$)
$$ p_k \cdot \ldots \cdot p_n = u_k $$
Which is a contraddiction (the product of prime elements cannot be invertible). So $m \geq k$ and
$$ p_k \cdot \ldots \cdot p_n = u_k q_k \cdots q_m $$
We can then apply the same argument I explained on top.

If otherwise m > n eventually you will have
$$ 1 = u_n q_n \cdot \ldots \cdot q_m $$
which is a contraddiction, as shown before
According to JayTuma you get (w.l.o.g. $i=1$):

$q_1\ldots q_m=p_1\ldots p_n=u_1q_1p_2\ldots p_n$

so $q_2\ldots q_m=u_1p_2\ldots p_n$ since every PID is an integral domain. Now substitute $p_2$ by (w.l.o.g.) $u_2q_2$ to get $q_3\ldots q_m=u_1u_2p_3\ldots p_n$ and so on. From this you easily deduce that $n$ has to be equal to $m$.