arr = []
0.upto(9999){|i|
    if i % 1111 != 0
        arr2 = sprintf("%04d", i).split("")
        arr3 = arr2.sort
        arr[i] = arr3.reverse.join.to_i - arr3.join.to_i
    end
}

while true
    n = gets.to_i
    break if n == 0
    if arr[n].nil?
        puts "NA"
    else
        count = 0
        until n == 6174
            n = arr[n]
            count += 1
        end
        puts count
    end
end
