construct a sequence which's sum is nearest the M