#include <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  string n;
  while (cin >> n, n != "0000") {
    int ans = 0;
    bool na = false;
    while (n != "6174") {
      sort(n.begin(), n.end());
      int s = stoi(n);
      sort(n.begin(), n.end(), greater<char>());
      int L = stoi(n);
      if (s == L) {
        cout << "NA\n";
        na = true;
        break;
      }
      ans++;
      ostringstream os;
      os << setfill('0') << setw(4) << L - s;
      n = os.str();
    }
    if (!na) cout << ans << "\n";
  }
}
