A Lagrangian Dynamical Theory for the Mass Function of Cosmic Structures - I. Dynamics