f=lambda s,c=0:s[1:]and f(min(s).join(`eval(s)`),c+1)or(s,c)
for s in '81+31', '351+14568', '21*111', '136*2356':
print '%-9s --> %s' % (s, f(s))
Zj1sYW1iZGEgcyxjPTA6c1sxOl1hbmQgZihtaW4ocykuam9pbihgZXZhbChzKWApLGMrMSlvcihzLGMpCgpmb3IgcyBpbiAnODErMzEnLCAnMzUxKzE0NTY4JywgJzIxKjExMScsICcxMzYqMjM1Nic6CglwcmludCAnJS05cyAtLT4gJXMnICUgKHMsIGYocykp