#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-9;
int main(){
    int n;
    while(cin>>n){
        if((n%10000)/1000==(n%1000)/100&&(n%1000)/100==(n%100)/10&&(n%100)/10==n%10){
            if(n%10==0){
                break;
            }
            cout<<"NA"<<endl;
            continue;
        }
    int c=0;
    while(n!=6174){
        int a[4];
        a[0]=(n%10000)/1000;
        a[1]=(n%1000)/100;
        a[2]=(n%100)/10;
        a[3]=n%10;
        int p;
        sort(a,a+4);
        p=1;
        int l=0,s=0;
        for(int i=0;i<4;i++){
            s+=a[i]*p;
            p*=10;
        }
        p=1;
        for(int i=3;i>=0;i--){
            l+=a[i]*p;
            p*=10;
        }
        n=s-l;
        c++;
    }
    cout<<c<<endl;
    }
}

