#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

int main(void){
	int a,b,c,d;
	while(scanf("%1d%1d%1d%1d",&a,&b,&c,&d)!=EOF,!(a==0&&b==0&&c==0&&d==0)){
		if(a==b&&b==c&&c==d&&d==a){
			cout<<"NA"<<endl;
		}else{
			int count=0;
			while(!(a==6&&b==1&&c==7&&d==4)){
				vector<int> nums,numl;
				nums.push_back(a);
				nums.push_back(b);
				nums.push_back(c);
				nums.push_back(d);
				numl = nums;
				sort(nums.begin(),nums.end());
				sort(numl.begin(),numl.end(),greater<int>());
				int s = nums[0]*1000+nums[1]*100+nums[2]*10+nums[3];
				int l = numl[0]*1000+numl[1]*100+numl[2]*10+numl[3];
				int N = l-s;
				a=N/1000;
				b=(N%1000)/100;
				c=(N%100)/10;
				d=N%10;
				++count;
			}
			cout<<count<<endl;
		}
	}
	return 0;
}