import scala.io.StdIn.readLine

object Main {
  def main(args:Array[String]):Unit = {
    println {
      Iterator.continually(readLine).takeWhile(_.toInt!=0).map { s=>
        var n = s
        var cnt = 0
        if(n.sortWith(_>_).toInt - n.sorted.toInt == 0) "NA"
        else {
          while(n!="6174") {
            n = "%04d".format((n.sortWith(_>_).toInt - n.sorted.toInt))
            cnt += 1
          }
          cnt
        }
      }.mkString("\n")
    }
  }
}