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

int main(){
	int n,nn;
	while(cin >> n,n){
		if(n % 1111 == 0) {
			cout << "NA" << endl;
		}else{
			int i = 0;
			for(;n != 6174;i++){
				int num[4] = {n / 1000,n / 100 % 10,n / 10 % 10,n % 10};
				sort(num,num + 4,greater<int>());
				n = num[0] * 1000 + num[1] * 100 + num[2] * 10 + num[3];
				sort(num,num + 4);
				nn = num[0] * 1000 + num[1] * 100 + num[2] * 10 + num[3];
				n = n - nn;
			}
			cout << i << endl;
		}
	}
	return 0;
}