#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
int main(){
	while(1){
		int n;
		int a[4]={1000,100,10,1};
		int l[4]={0},s[4]={0};
		int ans[4];
		cin>>n;
		if(n==0000)break;
		int cnt=0;
		int i,j;
		for(i=0;i<4;i++){
			l[i]=n/a[i];
			s[i]=l[i];
			n%=a[i];
		}
		if(l[0]==l[1]&&l[1]==l[2]&&l[2]==l[3])cout<<"NA"<<endl;
		else if(l[0]==6&&l[1]==1&&l[2]==7&&l[3]==4)cout<<0<<endl;
		else{
			while(1){
			for(i=0;i<4;i++){
				for(j=3;j>i;j--){
					if(l[i]<l[j]){
						swap(l[i],l[j]);
					}
					if(s[i]>s[j]){
						swap(s[i],s[j]);
					}
				}
			}
			cnt++;
				n=(l[0]*a[0]+l[1]*a[1]+l[2]*a[2]+l[3]*a[3])-(s[0]*a[0]+s[1]*a[1]+s[2]*a[2]+s[3]*a[3]);
						for(i=0;i<4;i++){
			l[i]=n/a[i];
			s[i]=l[i];
			ans[i]=l[i];
			n%=a[i];
		}
			if(ans[0]==6&&ans[1]==1&&ans[2]==7&&ans[3]==4){
				cout<<cnt<<endl;
				break;
			}
		}
		}
	}
	return 0;
}