### subroutines

def to6174(n)
  return $cache[n] if ! $cache[n].nil?

  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
  $cache[n] = to6174((l - s).to_s) + 1
end

### main

$cache = {}
$cache['6174'] = 0

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

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

  puts to6174(n)
end