main :: IO ()
main = do
  n <- getLine
  if n == "0000"
    then return ()
    else do
      putStrLn $ solve n
      main

solve :: String -> String
solve s
  | all ((==) (head s)) s = "NA"
  | otherwise = count s 0
  where
    count :: String -> Int -> String
    count s counter
      | s == "6174" = show counter
      | otherwise = count (show' ((read sorted) - (read (reverse sorted)))) (counter + 1)
      where
        sorted = sort s
        sort :: String -> String
        sort [] = []
        sort (x:xs) = (sort higher) ++ [x] ++ (sort lower)
          where
            higher = filter (\y -> y >= x) xs
            lower = filter (\y -> y < x) xs

        show' :: Int -> String
        show' n = (replicate (4 - (length n')) '0') ++ n'
          where n' = show n