#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

int main(){
    vector<int> n;
    int input;
    while(cin >> input){
        int ans = 0;
        if(input == 0) break;
        if(input % 1111 == 0){
            cout << "NA" << endl;
            continue;
        }
        while(input != 6174) {
            for(int i=0; i < 4; i++){
                n.push_back(input%10);
                input /= 10;
            }
            vector<int> minNum ,maxNum;

            sort(n.begin(), n.end());
            minNum = n;
            reverse(n.begin(), n.end());
            maxNum = n;

            int L=0, S=0;
            for(int i=0, m = 1000; i < 4; i++, m/=10){
                L += maxNum[i]*m;
                S += minNum[i]*m;
            }
            input = L-S;
            ans++;

            n.clear();
        }
        cout << ans << endl;
    }
}