#include<iostream>
#include<algorithm>
using namespace std;
int main(){
long n,d[4],l,s,k,i;
while(cin>>n,n){
for(k=0;n!=6174;k++){
for(i=0;i<4;i++){d[i]=n%10;n/=10;}
sort(d,d+4,greater<long>());
for(l=i=0;i<4;i++){l=l*10+d[i];}
sort(d,d+4);
for(s=i=0;i<4;i++){s=s*10+d[i];}
n=l-s;
if(n==0)break;
}
if(n==0)cout<<"NA"<<endl;else cout<<k<<endl;
}
return 0;
}