Dynamics of the head of gravity currents