#include <iostream>
#include <algorithm>

int main() {
	int n;
	int a[4] = {};

	while (std::cin >> n) {
		if (n == 0000)
			break;

		if (n % 1111 == 0) {
			std::cout << "NA" << std::endl;
			continue;
		}

		int count = 0;
		while (n != 6174) {
			a[0] = n / 1000, n %= 1000;
			a[1] = n / 100, n %= 100;
			a[2] = n / 10, n %= 10;
			a[3] = n;

			std::sort(a, a + 4);

			n = 0;
			n += (a[3] - a[0]) * 1000;
			n += (a[2] - a[1]) * 100;
			n += (a[1] - a[2]) * 10;
			n += a[0] - a[3];

			++count;
		}

		std::cout << count << std::endl;
	}
	return 0;
}