while line = gets.chomp
  if line == "0000"
    break
  elsif line.count(line[0]) == 4
    puts "NA"
    next
  end

  cnt = 0
  n = line
  while n != "6174"
    mini = n.split("").sort.join("")
    maxi = mini.reverse

    n = (maxi.to_i - mini.to_i).to_s.rjust(4, "0")
    cnt += 1
  end
  puts cnt
end