#include<iostream>
#include<algorithm>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

int mem[10000];

int next(int n) {
  int a[4];
  rep (i, 4) {
    a[i] = n % 10;
    n /= 10;
  }
  sort(a, a + 4);
  int p = 0, q = 0;
  rep (i, 4) p = p * 10 + a[i];
  rep (i, 4) q = q * 10 + a[3 - i];
  return q - p;
}

int solve(int n) {
  if (n == 6174) return 0;
  if (mem[n] != 0) return mem[n];
  return mem[n] = solve(next(n)) + 1;
}

int main() {
  int n;
  rep (i, 10) mem[1111 * i] = -1;
  while (true) {
    cin >> n;
    if (n == 0) break;
    if (mem[n] == -1) {
      cout << "NA" << endl;
      continue;
    }
    if (mem[n] != 0) {
      cout << mem[n] << endl;
      continue;
    }
    cout << solve(n) << endl;
  }
  return 0;
}