#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <functional>
#include <cmath>
using namespace std;

int main(void) {
	int S, L;
	string N;
	int ans;
	bool flag = false;

	while(1) {
flag=false;
		cin >> N;
		if(N[0] == N[1] && N[1] == N[2] && N[2] == N[3]) {
			flag = true;
			if(N[0] == '0')
				break;
		}

		if(!flag) {
			for(ans = 0; atoi(N.c_str()) != 6174; ans++) {
				sort(N.begin(), N.end());
				S = atoi(N.c_str());
				sort(N.begin(), N.end(), greater<int>());
				L = atoi(N.c_str());
				int tmp = L - S;

				for(int i = 1000, j = 0; i; i /= 10, j++) {
					N[j] = tmp / i + '0';
					tmp %= i;
				}
			}
		}

		if(flag)
			cout << "NA" << endl;
		else
			cout << ans << endl;
	}

	return 0;
}