Helper max and min distance