#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
	int num[4];
	int n;
	int l, s;
	
	while (cin >> n, n){
		int ct = 0;
		if (n % 1111 == 0){
			cout << "NA" << endl;
			continue;
		}
		while(n != 6174){
			l = s = 0;
			for (int i = 0; i < 4; i++){
				num[i] = n % 10;
				n /= 10;
			}
			sort(num, num + 4);
			
			for (int i = 0; i < 4; i++){
				s = s * 10 + num[i];
				l = l * 10 + num[3 - i];
			}
			n = l - s;
			ct++;
		}
		cout << ct << endl;
	}
	return (0);
}