### main

while true
  n = gets.strip
  break if n == '0000'

  if n.split('').uniq.length == 1
    puts 'NA'
    next
  end

  count = 0

  while n != '6174'
    ns = n.split('').map{|s| s.to_i}
    l = ns.sort{|a, b| b <=> a}.join('').to_i
    s = ns.sort{|a, b| a <=> b}.join('').to_i
    n = (l - s).to_s
    count += 1
  end

  puts count
end