#include<bits/stdc++.h>
#define endl '\n'
#define INF (1 << 21)
const int MOD = 1000000007;
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string str;
  int n;
  int l, s;
  int ans;

  cin >> str;
  while(str != "0000"){
    if(str == "6174"){
      cout << 0 << endl;
    }else if(str[0] == str[1] && str[1] == str[2] && str[2] == str[3]){
      cout << "NA" << endl;
    }else{
      ans = 0;

      while(1){
	l = s = 0;
	ans ++;

	int r = 1;
	sort(str.begin(), str.end());
	for(int i = 3;i >= 0;i--){
	  s += (str[i] - '0') * r;
	  r *= 10;
	}
	
	r = 1;
	reverse(str.begin(), str.end());
	for(int i = 3;i >= 0;i--){
	  l += (str[i] - '0') * r;
	  r *= 10;
	}
	
	if((n = l - s) == 6174){
	  break;
	}else{
	  for(int i = 3;i >= 0;i--){
	    str[i] = (n % 10) + '0';
	    n /= 10;
	  }
	}
      }
      cout << ans << endl;
    }      
    cin >> str;
  }
  return 0;
}


