I haven’t tested this, but I think, as you loop through the layers, you need to save off the shortest distance, and use that at the end, like this:
l = 0;
lMin = 999999;
for( i=1; i <= thisComp.numLayers; i++){
curLayer = thisComp.layer(i);
if(curLayer.name.slice(0, 3) == "C_M" && curLayer.effect("Circle Moving")("Fill Color") == 1) {
pointA = curLayer.toComp(position)[1];
pointB = thisLayer.toComp(position)[1];
l = length(pointA, pointB);
lMin = Math.min(l,lMin);
}
}
s = ease(lMin,0,200,53,33);
[s,s]