#include<bits/stdc++.h>
using namespace std;
int main(){
  string n;
  cin >>n;
  while(n!="0000"){
    int a[4];
    for(int i=0;i<4;i++){
      stringstream ss;
      ss <<n[i];
      ss >>a[i];
    }
    if((a[0]==a[1])&&(a[1]==a[2])&&(a[2]==a[3])){
      cout <<"NA"<<endl;
      cin >>n;
      continue;
    }
    for(int i=0;i<100;i++){
      if(n=="6174"){
        cout <<i <<endl;
        break;
      }
      sort(a,a+4);
      int l=a[0]+a[1]*10+a[2]*100+a[3]*1000;
      int s=a[3]+a[2]*10+a[1]*100+a[0]*1000;
      int n1=l-s;
      stringstream ss;
      ss << n1;
      ss >> n;
      if(n1<10){
        n.resize(4);
        n[3]=0;
        n[2]=0;
        n[1]=0;
      }else if(n1<100){
        n.resize(4);
        n[3]=0;
        n[2]=0;
      }else if(n1<1000){
        n.resize(4);
        n[3]=0;
      }
        for(int j=0;j<4;j++){
        stringstream ss1;
        ss1 <<n[j];
        ss1 >>a[j];
      }
    }
    cin >>n;
  }
  return 0;
}