#include <stdio.h>

int main(void)
{
	int N;
	int n[4] = {0};
	int L, S;
	int i;
	int x;
	int tmp;
	int k;
	int c;
	int h;
	
	c = 0;
	
	while (1){
		scanf("%d", &N);
		
		if (N == 0){
			break;
		}
		h = 0;
		while (1){
			if (N == 6174){
				break;
			}
			for (k = 0; k <= 3; k++){
				n[k] = N % 10;
				N /= 10;
			}
			if (n[0] == n[1] && n[1] == n[2] && n[2] == n[3]){
				h = 1;
				break;
			}
			for (i = 0; i <= 3; i++){
				for (x = 0; x <= 3; x++){
					if (n[i] > n[x]){
						tmp = n[x];
						n[x] = n[i];
						n[i] = tmp;
					}
				}
			}
			L = 0;
			for (k = 0; k <= 3; k++){
				L = L * 10 + n[k];
			}
		
				for (i = 0; i <= 3; i++){
				for (x = 0; x <= 3; x++){
					if (n[i] < n[x]){
						tmp = n[x];
						n[x] = n[i];
						n[i] = tmp;
					}
				}
			}
			S = 0;
			for (k = 0; k <= 3; k++){
				S = S * 10 + n[k];
			}
			N = L - S;
			c++;
			
		}
		if (h == 0){
			printf("%d\n", c);
			c = 0;
		}
		else {
			printf("NA\n");
		}
	}
	return (0);
}