def f(x)
    a = x.split("")
    return 'NA' if a.uniq.size == 1
    return 0 if x == "6174"
    sorted = a.sort
    l = sorted.reverse.join.to_i
    s = sorted.join.to_i
    return 1 + f(sprintf("%04d", (l - s)))
end

while gets
    break if $_ =~ /^0000$/
    puts f($_.chomp)
end