#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;

int N;
int Ns, Nl;
int num[4];
int S[4], L[4];
int result;

int main() {
    while (true) {
        result = 0;
        cin >> N;
        
        if (!N) break;            
        
        if (N != 6174) {
            num[0] = N / 1000;
            N %= 1000;
            num[1] = N / 100;
            N %= 100;
            num[2] = N / 10;
            N %= 10;
            num[3] = N;
            
            while (true) {
                Ns = 0; Nl = 0;
                int judge = 0;
                for (int i = 0; i < 4; i++) {
                    if (num[0] == num[i]) judge++;
                }

                if (judge == 4) {
                    cout << "NA" << endl;
                    break;
                }

                sort(num, num + 4);
                for (int i = 0; i < 4; i++) {
                    S[i] = num[i];
                }

                Ns += S[0] * 1000;
                Ns += S[1] * 100;
                Ns += S[2] * 10;
                Ns += S[3];

                sort(num, num + 4, greater<int>());
                for (int i = 0; i < 4; i++) {
                    L[i] = num[i];
                }

                Nl += L[0] * 1000;
                Nl += L[1] * 100;
                Nl += L[2] * 10;
                Nl += L[3];

                N = Nl - Ns;

                num[0] = N / 1000;
                N %= 1000;
                num[1] = N / 100;
                N %= 100;
                num[2] = N / 10;
                N %= 10;
                num[3] = N;

                result++;

                if(num[0] == 6 && num[1] == 1 && num[2] == 7 && num[3] == 4) {
                    cout << result << endl;
                    break;
                }
            }
        }
        else cout << 0 << endl;
        
    }
    
    return 0;
}