Solve lcsm problem