Second-order integrable Lagrangians and WDVV equations