how is this conversion possible?
I am confused why NOT1 was replaced with NAND4?


First, it sould be clear why it was legitimate to do so - a NAND gate with the inputs joined is just an inverter.

To understand the motivation why it was done, it's useful to look at the final OR gate preceded by inverters on each input, and realize that DeMorgan's theorem shows that the OR with inverted inputs can be replaced by a NAND gate.

At that point you have a circuit made of 4 NAND gates, and in traditional 74xx logic families, NAND gates happen to come four to an IC package... ie, the 74xx00 is a quad two input NAND.