#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(){
  while(true){
    string s;cin>>s;
    if(s=="0000"){
      return 0;
    }
    int k = 0;
    while(true){
      if(s=="6174"){
        cout << k << endl;
        break;
      }
      k++;
      sort(s.begin(),s.end());
      //cout <<"!!" <<s << endl;
      int a = 0;
      for(int i = 0; 4 > i; i++){
        a*=10;
        a+=s[i]-'0';
        //cout << a << endl;
      }
      int b = 0;
      for(int i = 3; 0 <= i; i--){
        b*=10;
        b+=s[i]-'0';
      }
      //cout << a << " " << b << endl;
      int c = b-a;
      //cout <<c << endl;
      if(c == 0){
        cout << "NA" << endl;
        break;
      }
      if(c == 6174){
        cout << k << endl;
        break;
      }
      s[0] = c/1000;
      s[1] = (c/100)%10;
      s[2] = (c/10)%10;
      s[3] = c%10;
    }
  }
}
