Measurement of the moments of the hadronic invariant mass distribution in semileptonic B decays