This has to do with the fact that the cumulative histogram starts at 1 and not 0 as according to it mathematical formula: http://en.wikipedia.org/wiki/Histogram#Cumulative_histogram

For your example the following applies:
while(values[254 + 1] <= 255)  #TRUE#
 minColor = 254 + 1 #255#

return minColor #255#

To simplify this I could just start with minColor = 1 and skip addition on every loop.