#include <iostream>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
using namespace std;

string toString(int n){
  ostringstream oss;
  oss << n;
  return oss.str();
}

int toInt(string s){
  istringstream iss(s);
  int ret;
  iss >> ret;
  return ret;
}


int main(){
  string s;
  while(cin >> s){
    if(s == "0000") break;
    if(s[0] == s[1] && s[1] == s[2] && s[2] == s[3]){
      cout << "NA" << endl;
      continue;
    }
    int cnt = 0;
    bool f = false;
    while(s != "6174"){
    if(s[0] == s[1] && s[1] == s[2] && s[2] == s[3]){
      cout <<"NA"<<endl;
      f = true;
      break;
    }
      cnt++;
      string L, S;
      L = s;
      sort(L.begin(), L.end());
      S = L;
      reverse(L.begin(), L.end());
      int a, b;
      a = toInt(L);
      b = toInt(S);
      s = toString(a-b);
      while(s.size() != 4){
	s += "0";
      }
    }
    if(!f)cout << cnt << endl;
  }
  return 0;
}