function f(s,M)if s==""then return""else for l=1,#s do x=s:sub(-l)if x:sub(1,1)~="0"then if M==N or#x<#M or#x==#M and x<M then if f(s:sub(1,-l-1),x)then return l end end end end return N end end while""do print(f(io.read()))end
Note that non-ascii characters in the above source code will be escaped (such as \x9f).