#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <iostream>
using namespace std;

string operator-(const string &a, const string &b) {
	char buff[128];
	sprintf(buff, "%04d", stoi(a) - stoi(b));
	return string(buff);
}

int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	const string goal = "6174";

	for(string n; cin >> n && n != "0000";) {
		if(all_of(n.begin(), n.end(), [&](char c) { return c == n.front(); })) {
			cout << "NA" << endl;
			continue;
		}

		int cnt = 0;
		while(n != goal) {
			string L(n), S(n);
			sort(L.rbegin(), L.rend());
			sort(S.begin(), S.end());
			n = L - S;
			++cnt;
		}

		cout << cnt << endl;
	}

	return EXIT_SUCCESS;
}