#include<bits/stdc++.h>
using namespace std;
int main(void){
	string s,ss,sss;
	int i,j;
	int x,y;
	int z;
	int flg;
	while(1){
		cin>>s;
		if(s=="0000")	break;
		flg=0;
		for(i=0;i<3;i++){
			if(s[i]!=s[i+1]){
				flg=1;
				break;
			}
		}
		if(flg==1){
			j=1;
			if(s=="6174")	j=0;
			else{
				while(1){
					if(s=="6174")	break;
					ss=s;
					sort(ss.begin(),ss.end(),greater<char>());
					if(ss=="6174")	break;
					sss=s;
					sort(sss.begin(),sss.end());
					if(sss=="6174")	break;
					z=1000;
					x=y=0;
					for(i=0;i<4;i++){
						x+=(ss[i]-'0')*z;
						y+=(sss[i]-'0')*z;
						z/=10;
					}
					//cout<<x<<" "<<y<<endl;
					z=x-y;
					//cout<<z<<endl;
					for(i=3;i>=0;i--){
						s[i]=(z%10)+'0';
						z/=10;
					}
					//cout<<s<<endl;
					if(s=="6174")	break;
					j++;
				}
			}
		}
		if(flg==1)	cout<<j<<endl;
		else 		cout<<"NA"<<endl;
	}
	return 0;
}
		
	
